Skip to content

Commit 574552f

Browse files
Enable zooming on macOS WebKit control with Command +/- keys
If keydown events for Command +/= or Command - are not consumed by any event handler, invoke the native methods `makeTextLarger` or `makeTextSmaller` on the WebKit control to provide zooming functionality on macOS.
1 parent 84e6db7 commit 574552f

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,8 @@ public static Selector getSelector (long value) {
991991
public static final long sel_canBecomeKeyWindow = Selector.sel_canBecomeKeyWindow.value;
992992
public static final long sel_canDragRowsWithIndexes_atPoint_ = Selector.sel_canDragRowsWithIndexes_atPoint_.value;
993993
public static final long sel_canGoBack = Selector.sel_canGoBack.value;
994+
public static final long sel_makeTextLarger = Selector.sel_makeTextLarger.value;
995+
public static final long sel_makeTextSmaller = Selector.sel_makeTextSmaller.value;
994996
public static final long sel_canGoForward = Selector.sel_canGoForward.value;
995997
public static final long sel_canRedo = Selector.sel_canRedo.value;
996998
public static final long sel_canShowMIMEType_ = Selector.sel_canShowMIMEType_.value;

bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public enum Selector {
234234
, sel_canBecomeKeyWindow("canBecomeKeyWindow")
235235
, sel_canDragRowsWithIndexes_atPoint_("canDragRowsWithIndexes:atPoint:")
236236
, sel_canGoBack("canGoBack")
237+
, sel_makeTextLarger("makeTextLarger:")
238+
, sel_makeTextSmaller("makeTextSmaller:")
237239
, sel_canGoForward("canGoForward")
238240
, sel_canRedo("canRedo")
239241
, sel_canShowMIMEType_("canShowMIMEType:")

bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/WebView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public boolean canGoBack() {
3131
return OS.objc_msgSend_bool(this.id, OS.sel_canGoBack);
3232
}
3333

34+
public void makeTextLarger() {
35+
OS.objc_msgSend(this.id, OS.sel_makeTextLarger);
36+
}
37+
38+
public void makeTextSmaller() {
39+
OS.objc_msgSend(this.id, OS.sel_makeTextSmaller);
40+
}
41+
3442
public boolean canGoForward() {
3543
return OS.objc_msgSend_bool(this.id, OS.sel_canGoForward);
3644
}

bundles/org.eclipse.swt/Eclipse SWT WebKit/cocoa/org/eclipse/swt/browser/WebKit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,10 @@ void handleEvent(long evtId) {
15861586
} else if (translatedKey == 'x') {
15871587
webView.cut (webView);
15881588
event.preventDefault();
1589+
} else if (translatedKey == '=' || translatedKey == '+') {
1590+
webView.makeTextLarger();
1591+
} else if (translatedKey == '-') {
1592+
webView.makeTextSmaller();
15891593
}
15901594
}
15911595
}

0 commit comments

Comments
 (0)