Browse Source

HandleKeyboardEvent returns bool

https://chromium-review.googlesource.com/c/chromium/src/+/1262404
Jeremy Apthorp 6 years ago
parent
commit
30e5e993c1

+ 3 - 3
atom/browser/api/atom_api_web_contents.cc

@@ -617,15 +617,15 @@ void WebContents::UpdateTargetURL(content::WebContents* source,
   Emit("update-target-url", url);
 }
 
-void WebContents::HandleKeyboardEvent(
+bool WebContents::HandleKeyboardEvent(
     content::WebContents* source,
     const content::NativeWebKeyboardEvent& event) {
   if (type_ == WEB_VIEW && embedder_) {
     // Send the unhandled keyboard events back to the embedder.
-    embedder_->HandleKeyboardEvent(source, event);
+    return embedder_->HandleKeyboardEvent(source, event);
   } else {
     // Go to the default keyboard handling.
-    CommonWebContentsDelegate::HandleKeyboardEvent(source, event);
+    return CommonWebContentsDelegate::HandleKeyboardEvent(source, event);
   }
 }
 

+ 1 - 1
atom/browser/api/atom_api_web_contents.h

@@ -362,7 +362,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
   void CloseContents(content::WebContents* source) override;
   void ActivateContents(content::WebContents* contents) override;
   void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
-  void HandleKeyboardEvent(
+  bool HandleKeyboardEvent(
       content::WebContents* source,
       const content::NativeWebKeyboardEvent& event) override;
   content::KeyboardEventProcessingResult PreHandleKeyboardEvent(

+ 1 - 1
atom/browser/common_web_contents_delegate.h

@@ -100,7 +100,7 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate,
       content::WebContents* web_contents,
       content::SecurityStyleExplanations* explanations) override;
   bool TakeFocus(content::WebContents* source, bool reverse) override;
-  void HandleKeyboardEvent(
+  bool HandleKeyboardEvent(
       content::WebContents* source,
       const content::NativeWebKeyboardEvent& event) override;
 

+ 12 - 5
atom/browser/common_web_contents_delegate_mac.mm

@@ -17,12 +17,12 @@
 
 namespace atom {
 
-void CommonWebContentsDelegate::HandleKeyboardEvent(
+bool CommonWebContentsDelegate::HandleKeyboardEvent(
     content::WebContents* source,
     const content::NativeWebKeyboardEvent& event) {
   if (event.skip_in_browser ||
       event.GetType() == content::NativeWebKeyboardEvent::kChar)
-    return;
+    return false;
 
   // Escape exits tabbed fullscreen mode.
   if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen()) {
@@ -34,16 +34,23 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
   auto* web_preferences = WebContentsPreferences::From(source);
   if (web_preferences &&
       web_preferences->IsEnabled("ignoreMenuShortcuts", false))
-    return;
+    return false;
 
   // Send the event to the menu before sending it to the window
   if (event.os_event.type == NSKeyDown &&
       [[NSApp mainMenu] performKeyEquivalent:event.os_event])
-    return;
+    return true;
 
   if (event.os_event.window &&
-      [event.os_event.window isKindOfClass:[EventDispatchingWindow class]])
+      [event.os_event.window isKindOfClass:[EventDispatchingWindow class]]) {
     [event.os_event.window redispatchKeyEvent:event.os_event];
+    // FIXME(nornagon): this isn't the right return value; we should implement
+    // devtools windows as Widgets in order to take advantage of the
+    // pre-existing redispatch code in bridged_native_widget.
+    return false;
+  }
+
+  return false;
 }
 
 }  // namespace atom

+ 6 - 3
atom/browser/common_web_contents_delegate_views.cc

@@ -17,25 +17,28 @@
 
 namespace atom {
 
-void CommonWebContentsDelegate::HandleKeyboardEvent(
+bool CommonWebContentsDelegate::HandleKeyboardEvent(
     content::WebContents* source,
     const content::NativeWebKeyboardEvent& event) {
   // Escape exits tabbed fullscreen mode.
   if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen()) {
     ExitFullscreenModeForTab(source);
-    return;
+    return true;
   }
 
   // Check if the webContents has preferences and to ignore shortcuts
   auto* web_preferences = WebContentsPreferences::From(source);
   if (web_preferences &&
       web_preferences->IsEnabled("ignoreMenuShortcuts", false))
-    return;
+    return false;
 
   // Let the NativeWindow handle other parts.
   if (owner_window()) {
     owner_window()->HandleKeyboardEvent(source, event);
+    return true;
   }
+
+  return false;
 }
 
 void CommonWebContentsDelegate::ShowAutofillPopup(

+ 2 - 3
atom/browser/ui/inspectable_web_contents_impl.cc

@@ -779,12 +779,11 @@ bool InspectableWebContentsImpl::ShouldCreateWebContents(
   return false;
 }
 
-void InspectableWebContentsImpl::HandleKeyboardEvent(
+bool InspectableWebContentsImpl::HandleKeyboardEvent(
     content::WebContents* source,
     const content::NativeWebKeyboardEvent& event) {
   auto* delegate = web_contents_->GetDelegate();
-  if (delegate)
-    delegate->HandleKeyboardEvent(source, event);
+  return !delegate || delegate->HandleKeyboardEvent(source, event);
 }
 
 void InspectableWebContentsImpl::CloseContents(content::WebContents* source) {

+ 1 - 1
atom/browser/ui/inspectable_web_contents_impl.h

@@ -182,7 +182,7 @@ class InspectableWebContentsImpl
       const GURL& target_url,
       const std::string& partition_id,
       content::SessionStorageNamespace* session_storage_namespace) override;
-  void HandleKeyboardEvent(content::WebContents*,
+  bool HandleKeyboardEvent(content::WebContents*,
                            const content::NativeWebKeyboardEvent&) override;
   void CloseContents(content::WebContents* source) override;
   content::ColorChooser* OpenColorChooser(