diff options
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/interstitial_page.cc | 18 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_delegate.h | 14 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view.cc | 14 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view.h | 12 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.cc | 30 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.h | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.mm | 49 |
8 files changed, 38 insertions, 101 deletions
diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index aae90da..7212566 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -98,8 +98,9 @@ class InterstitialPage::InterstitialPageRVHViewDelegate virtual void UpdateDragCursor(WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); - virtual bool IsReservedAccelerator(const NativeWebKeyboardEvent& event); - virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event); + virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut); + virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); virtual void HandleMouseEvent(); virtual void HandleMouseLeave(); virtual void OnFindReply(int request_id, @@ -586,17 +587,18 @@ void InterstitialPage::InterstitialPageRVHViewDelegate::TakeFocus( interstitial_page_->tab()->GetViewDelegate()->TakeFocus(reverse); } -bool InterstitialPage::InterstitialPageRVHViewDelegate::IsReservedAccelerator( - const NativeWebKeyboardEvent& event) { +bool InterstitialPage::InterstitialPageRVHViewDelegate::PreHandleKeyboardEvent( + const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { + if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) + return interstitial_page_->tab()->GetViewDelegate()->PreHandleKeyboardEvent( + event, is_keyboard_shortcut); return false; } -bool InterstitialPage::InterstitialPageRVHViewDelegate::HandleKeyboardEvent( +void InterstitialPage::InterstitialPageRVHViewDelegate::HandleKeyboardEvent( const NativeWebKeyboardEvent& event) { if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) - return interstitial_page_->tab()->GetViewDelegate()-> - HandleKeyboardEvent(event); - return false; + interstitial_page_->tab()->GetViewDelegate()->HandleKeyboardEvent(event); } void InterstitialPage::InterstitialPageRVHViewDelegate::HandleMouseEvent() { diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index 8e1379d..f67d8bb 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -222,18 +222,18 @@ class TabContentsDelegate { bool show_history) { } - // Returns whether the event is a reserved keyboard shortcut that should not - // be sent to the renderer. - virtual bool IsReservedAccelerator(const NativeWebKeyboardEvent& event) { + // Allows delegates to handle keyboard events before sending to the renderer. + // Returns true if the |event| was handled. Otherwise, if the |event| would be + // handled in HandleKeyboardEvent() method as a normal keyboard shortcut, + // |*is_keyboard_shortcut| should be set to true. + virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut) { return false; } // Allows delegates to handle unhandled keyboard messages coming back from // the renderer. - // Returns true if the keyboard message was handled. - virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { - return false; - } + virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} // Shows the repost form confirmation dialog box. virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) {} diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index 9505069..533e6dc 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -58,10 +58,16 @@ void TabContentsView::ShowCreatedWidget(int route_id, ShowCreatedWidgetInternal(widget_host_view, initial_pos); } -bool TabContentsView::IsReservedAccelerator( - const NativeWebKeyboardEvent& event) { - return tab_contents()->delegate() && - tab_contents()->delegate()->IsReservedAccelerator(event); +bool TabContentsView::PreHandleKeyboardEvent( + const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { + return tab_contents_->delegate() && + tab_contents_->delegate()->PreHandleKeyboardEvent( + event, is_keyboard_shortcut); +} + +void TabContentsView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { + if (tab_contents_->delegate()) + tab_contents_->delegate()->HandleKeyboardEvent(event); } RenderWidgetHostView* TabContentsView::CreateNewWidgetInternal( diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index 4f55ab5..a7ca049 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -115,6 +115,17 @@ class TabContentsView : public RenderViewHostDelegate::View { // invoked, SetInitialFocus is invoked. virtual void RestoreFocus() = 0; + // Keyboard events forwarding from the RenderViewHost. + // The default implementation just forward the events to the + // TabContentsDelegate object. + virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut); + + // Keyboard events forwarding from the RenderViewHost. + // The default implementation just forward the events to the + // TabContentsDelegate object. + virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); + // Simple mouse event forwarding from the RenderViewHost. virtual void HandleMouseEvent() {} virtual void HandleMouseLeave() {} @@ -175,7 +186,6 @@ class TabContentsView : public RenderViewHostDelegate::View { bool user_gesture, const GURL& creator_url); virtual void ShowCreatedWidget(int route_id, const gfx::Rect& initial_pos); - virtual bool IsReservedAccelerator(const NativeWebKeyboardEvent& event); // The TabContents whose contents we display. TabContents* tab_contents_; diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index d0a2635..f37e3e6 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -318,36 +318,6 @@ void TabContentsViewGtk::TakeFocus(bool reverse) { } } -bool TabContentsViewGtk::HandleKeyboardEvent( - const NativeWebKeyboardEvent& event) { - // This may be an accelerator. Try to pass it on to our browser window - // to handle. - GtkWindow* window = GetTopLevelNativeWindow(); - if (!window) { - NOTREACHED(); - return false; - } - - // Filter out pseudo key events created by GtkIMContext signal handlers. - // Since GtkIMContext signal handlers don't use GdkEventKey objects, its - // |event.os_event| values are dummy values (or NULL.) - // We should filter out these pseudo key events to prevent unexpected - // behaviors caused by them. - // We should also filter out the KeyUp event as it should not be processed - // as an accelerator. - if (event.type == WebKit::WebInputEvent::Char || - event.type == WebKit::WebInputEvent::KeyUp) - return false; - - BrowserWindowGtk* browser_window = - BrowserWindowGtk::GetBrowserWindowForNativeWindow(window); - - // If this is a dialog, the top level window isn't a browser. In this case, - // we just return false. - return browser_window ? - browser_window->HandleKeyboardEvent(event.os_event) : false; -} - void TabContentsViewGtk::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index 6e60232..61e5e21 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -69,7 +69,6 @@ class TabContentsViewGtk : public TabContentsView, virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); - virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event); // NotificationObserver implementation --------------------------------------- diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h index 4da8267..c3801a7 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.h +++ b/chrome/browser/tab_contents/tab_contents_view_mac.h @@ -77,7 +77,6 @@ class TabContentsViewMac : public TabContentsView, virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); - virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event); // NotificationObserver implementation --------------------------------------- diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 763aa3b..14b16c6 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -47,7 +47,6 @@ COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); @interface TabContentsViewCocoa (Private) - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; -- (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)event; - (void)registerDragTypes; - (void)setCurrentDragOperation:(NSDragOperation)operation; - (void)startDragWithDropData:(const WebDropData&)dropData @@ -231,12 +230,6 @@ void TabContentsViewMac::TakeFocus(bool reverse) { } } -bool TabContentsViewMac::HandleKeyboardEvent( - const NativeWebKeyboardEvent& event) { - return [cocoa_view_.get() processKeyboardEvent: - const_cast<NativeWebKeyboardEvent*>(&event)] == YES; -} - void TabContentsViewMac::ShowContextMenu(const ContextMenuParams& params) { RenderViewContextMenuMac menu(tab_contents(), params, @@ -355,48 +348,6 @@ void TabContentsViewMac::Observe(NotificationType type, return tabContentsView_->tab_contents(); } -- (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)wkEvent { - if (wkEvent->skip_in_browser || wkEvent->type == WebKit::WebInputEvent::Char) - return NO; - - NSEvent* event = wkEvent->os_event; - DCHECK(event != NULL); - - // If this tab is no longer active, its window will be |nil|. In that case, - // best ignore the event. - if (![self window]) - return NO; - ChromeEventProcessingWindow* window = - (ChromeEventProcessingWindow*)[self window]; - DCHECK([window isKindOfClass:[ChromeEventProcessingWindow class]]); - - // Do not fire shortcuts on key up. - if ([event type] == NSKeyDown) { - // Send the event to the menu before sending it to the browser/window - // shortcut handling, so that if a user configures cmd-left to mean - // "previous tab", it takes precedence over the built-in "history back" - // binding. Other than that, the |redispatchEvent| call would take care of - // invoking the original menu item shortcut as well. - if ([[NSApp mainMenu] performKeyEquivalent:event]) - return YES; - - if ([window handleExtraBrowserKeyboardShortcut:event]) - return YES; - if ([window handleExtraWindowKeyboardShortcut:event]) - return YES; - } - - // We need to re-dispatch the event, so that it is sent to the menu or other - // cocoa mechanisms (such as the cmd-` handler). - RenderWidgetHostViewCocoa* rwhv = static_cast<RenderWidgetHostViewCocoa*>( - tabContentsView_->GetContentNativeView()); - DCHECK([rwhv isKindOfClass:[RenderWidgetHostViewCocoa class]]); - [rwhv setIgnoreKeyEvents:YES]; - BOOL eventHandled = [window redispatchEvent:event]; - [rwhv setIgnoreKeyEvents:NO]; - return eventHandled; -} - - (void)mouseEvent:(NSEvent *)theEvent { TabContents* tabContents = [self tabContents]; if (tabContents->delegate()) { |