| 1 | //go:build windows |
| 2 | |
| 3 | package edge |
| 4 | |
| 5 | import ( |
| 6 | "golang.org/x/sys/windows" |
| 7 | "syscall" |
| 8 | "unsafe" |
| 9 | ) |
| 10 | |
| 11 | type ICoreWebView2Controller3Vtbl struct { |
| 12 | _IUnknownVtbl |
| 13 | GetIsVisible ComProc |
| 14 | PutIsVisible ComProc |
| 15 | GetBounds ComProc |
| 16 | PutBounds ComProc |
| 17 | GetZoomFactor ComProc |
| 18 | PutZoomFactor ComProc |
| 19 | AddZoomFactorChanged ComProc |
| 20 | RemoveZoomFactorChanged ComProc |
| 21 | SetBoundsAndZoomFactor ComProc |
| 22 | MoveFocus ComProc |
| 23 | AddMoveFocusRequested ComProc |
| 24 | RemoveMoveFocusRequested ComProc |
| 25 | AddGotFocus ComProc |
| 26 | RemoveGotFocus ComProc |
| 27 | AddLostFocus ComProc |
| 28 | RemoveLostFocus ComProc |
| 29 | AddAcceleratorKeyPressed ComProc |
| 30 | RemoveAcceleratorKeyPressed ComProc |
| 31 | GetParentWindow ComProc |
| 32 | PutParentWindow ComProc |
| 33 | NotifyParentWindowPositionChanged ComProc |
| 34 | Close ComProc |
| 35 | GetCoreWebView2 ComProc |
| 36 | GetDefaultBackgroundColor ComProc |
| 37 | PutDefaultBackgroundColor ComProc |
| 38 | GetRasterizationScale ComProc |
| 39 | PutRasterizationScale ComProc |
| 40 | GetShouldDetectMonitorScaleChanges ComProc |
| 41 | PutShouldDetectMonitorScaleChanges ComProc |
| 42 | AddRasterizationScaleChanged ComProc |
| 43 | RemoveRasterizationScaleChanged ComProc |
| 44 | GetBoundsMode ComProc |
| 45 | PutBoundsMode ComProc |
| 46 | } |
| 47 | |
| 48 | type ICoreWebView2Controller3 struct { |
| 49 | Vtbl *ICoreWebView2Controller3Vtbl |
| 50 | } |
| 51 | |
| 52 | func (i *ICoreWebView2Controller3) AddRef() uintptr { |
| 53 | refCounter, _, _ := i.Vtbl.AddRef.Call(uintptr(unsafe.Pointer(i))) |
| 54 | return refCounter |
| 55 | } |
| 56 | |
| 57 | func (i *ICoreWebView2Controller) GetICoreWebView2Controller3() *ICoreWebView2Controller3 { |
| 58 | var result *ICoreWebView2Controller3 |
| 59 | |
| 60 | iidICoreWebView2Controller3 := NewGUID("{f9614724-5d2b-41dc-aef7-73d62b51543b}") |
| 61 | _, _, _ = i.vtbl.QueryInterface.Call( |
| 62 | uintptr(unsafe.Pointer(i)), |
| 63 | uintptr(unsafe.Pointer(iidICoreWebView2Controller3)), |
| 64 | uintptr(unsafe.Pointer(&result))) |
| 65 | |
| 66 | return result |
| 67 | } |
| 68 | |
| 69 | func (i *ICoreWebView2Controller3) GetRasterizationScale() (float64, error) { |
| 70 | |
| 71 | var scale float64 |
| 72 | |
| 73 | hr, _, _ := i.Vtbl.GetRasterizationScale.Call( |
| 74 | uintptr(unsafe.Pointer(i)), |
| 75 | uintptr(unsafe.Pointer(&scale)), |
| 76 | ) |
| 77 | if windows.Handle(hr) != windows.S_OK { |
| 78 | return 0.0, syscall.Errno(hr) |
| 79 | } |
| 80 | return scale, nil |
| 81 | } |
| 82 | |
| 83 | func (i *ICoreWebView2Controller3) PutRasterizationScale(scale float64) error { |
| 84 | |
| 85 | hr, _, _ := i.Vtbl.PutRasterizationScale.Call( |
| 86 | uintptr(unsafe.Pointer(i)), |
| 87 | uintptr(unsafe.Pointer(&scale)), |
| 88 | ) |
| 89 | if windows.Handle(hr) != windows.S_OK { |
| 90 | return syscall.Errno(hr) |
| 91 | } |
| 92 | return nil |
| 93 | } |
| 94 | |
| 95 | func (i *ICoreWebView2Controller3) GetShouldDetectMonitorScaleChanges() (bool, error) { |
| 96 | // Create int32 to hold bool result |
| 97 | var _value int32 |
| 98 | |
| 99 | hr, _, _ := i.Vtbl.GetShouldDetectMonitorScaleChanges.Call( |
| 100 | uintptr(unsafe.Pointer(i)), |
| 101 | uintptr(unsafe.Pointer(&_value)), |
| 102 | ) |
| 103 | if windows.Handle(hr) != windows.S_OK { |
| 104 | return false, syscall.Errno(hr) |
| 105 | } |
| 106 | // Get result and cleanup |
| 107 | value := _value != 0 |
| 108 | return value, nil |
| 109 | } |
| 110 | |
| 111 | func (i *ICoreWebView2Controller3) PutShouldDetectMonitorScaleChanges(value bool) error { |
| 112 | |
| 113 | hr, _, _ := i.Vtbl.PutShouldDetectMonitorScaleChanges.Call( |
| 114 | uintptr(unsafe.Pointer(i)), |
| 115 | uintptr(boolToInt(value)), |
| 116 | ) |
| 117 | if windows.Handle(hr) != windows.S_OK { |
| 118 | return syscall.Errno(hr) |
| 119 | } |
| 120 | return nil |
| 121 | } |
| 122 | |
| 123 | func (i *ICoreWebView2Controller3) AddRasterizationScaleChanged(eventHandler *ICoreWebView2RasterizationScaleChangedEventHandler) (EventRegistrationToken, error) { |
| 124 | |
| 125 | var token EventRegistrationToken |
| 126 | |
| 127 | hr, _, _ := i.Vtbl.AddRasterizationScaleChanged.Call( |
| 128 | uintptr(unsafe.Pointer(i)), |
| 129 | uintptr(unsafe.Pointer(eventHandler)), |
| 130 | uintptr(unsafe.Pointer(&token)), |
| 131 | ) |
| 132 | if windows.Handle(hr) != windows.S_OK { |
| 133 | return EventRegistrationToken{}, syscall.Errno(hr) |
| 134 | } |
| 135 | return token, nil |
| 136 | } |
| 137 | |
| 138 | func (i *ICoreWebView2Controller3) RemoveRasterizationScaleChanged(token EventRegistrationToken) error { |
| 139 | |
| 140 | hr, _, _ := i.Vtbl.RemoveRasterizationScaleChanged.Call( |
| 141 | uintptr(unsafe.Pointer(i)), |
| 142 | uintptr(unsafe.Pointer(&token)), |
| 143 | ) |
| 144 | if windows.Handle(hr) != windows.S_OK { |
| 145 | return syscall.Errno(hr) |
| 146 | } |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | func (i *ICoreWebView2Controller3) GetBoundsMode() (COREWEBVIEW2_BOUNDS_MODE, error) { |
| 151 | |
| 152 | var boundsMode COREWEBVIEW2_BOUNDS_MODE |
| 153 | |
| 154 | hr, _, _ := i.Vtbl.GetBoundsMode.Call( |
| 155 | uintptr(unsafe.Pointer(i)), |
| 156 | uintptr(unsafe.Pointer(&boundsMode)), |
| 157 | ) |
| 158 | if windows.Handle(hr) != windows.S_OK { |
| 159 | return 0, syscall.Errno(hr) |
| 160 | } |
| 161 | return boundsMode, nil |
| 162 | } |
| 163 | |
| 164 | func (i *ICoreWebView2Controller3) PutBoundsMode(boundsMode COREWEBVIEW2_BOUNDS_MODE) error { |
| 165 | |
| 166 | hr, _, _ := i.Vtbl.PutBoundsMode.Call( |
| 167 | uintptr(unsafe.Pointer(i)), |
| 168 | uintptr(boundsMode), |
| 169 | ) |
| 170 | if windows.Handle(hr) != windows.S_OK { |
| 171 | return syscall.Errno(hr) |
| 172 | } |
| 173 | return nil |
| 174 | } |
| 175 |