diff options
30 files changed, 124 insertions, 18 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 6083fb0..ed40e3e 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2742,6 +2742,14 @@ bool Browser::TakeFocus(bool reverse) { return false; } +void Browser::Activate() { + window_->Activate(); +} + +void Browser::Deactivate() { + window_->Deactivate(); +} + bool Browser::IsApplication() const { return (type_ & TYPE_APP) != 0; } diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 0a7c0ab..f01c8be 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -711,6 +711,8 @@ class Browser : public TabStripModelDelegate, virtual void SetTabContentBlocked(TabContents* contents, bool blocked); virtual void TabContentsFocused(TabContents* tab_content); virtual bool TakeFocus(bool reverse); + virtual void Activate(); + virtual void Deactivate(); virtual bool IsApplication() const; virtual void ConvertContentsToApplication(TabContents* source); virtual bool ShouldDisplayURLField(); diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index 859d0e7..0b679ab 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -60,6 +60,10 @@ class BrowserWindow { // state if necessary. virtual void Activate() = 0; + // Deactivates the window, making the next window in the Z order the active + // window. + virtual void Deactivate() = 0; + // Returns true if the window is currently the active/focused window. virtual bool IsActive() const = 0; diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index 4559567..68e7061 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -35,6 +35,7 @@ class BrowserWindowCocoa : public BrowserWindow, virtual void SetBounds(const gfx::Rect& bounds); virtual void Close(); virtual void Activate(); + virtual void Deactivate(); virtual bool IsActive() const; virtual void FlashFrame(); virtual gfx::NativeWindow GetNativeHandle(); diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 61420d0..33bbc73 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -108,6 +108,11 @@ void BrowserWindowCocoa::Activate() { [controller_ activate]; } +void BrowserWindowCocoa::Deactivate() { + // TODO(jcivelli): http://crbug.com/51364 Implement me. + NOTIMPLEMENTED(); +} + void BrowserWindowCocoa::FlashFrame() { [NSApp requestUserAttention:NSInformationalRequest]; } diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 2265793..49e84ba 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -654,6 +654,12 @@ void ExtensionHost::GotFocus() { void ExtensionHost::TakeFocus(bool reverse) { } +void ExtensionHost::Activate() { +} + +void ExtensionHost::Deactivate() { +} + bool ExtensionHost::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { if (extension_host_type_ == ViewType::EXTENSION_POPUP && diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 281953f..253c4f4 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -165,6 +165,8 @@ class ExtensionHost : public RenderViewHostDelegate, virtual void UpdateDragCursor(WebKit::WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); + virtual void Activate(); + virtual void Deactivate(); virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut); virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index e81bca9..b9392bc 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -711,6 +711,11 @@ void BrowserWindowGtk::Activate() { gtk_window_present(window_); } +void BrowserWindowGtk::Deactivate() { + // TODO(jcivelli): http://crbug.com/51364 Implement me. + NOTIMPLEMENTED(); +} + bool BrowserWindowGtk::IsActive() const { return is_active_; } diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 085d8ff..f2bc145 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -53,6 +53,7 @@ class BrowserWindowGtk : public BrowserWindow, virtual void SetBounds(const gfx::Rect& bounds); virtual void Close(); virtual void Activate(); + virtual void Deactivate(); virtual bool IsActive() const; virtual void FlashFrame(); virtual gfx::NativeWindow GetNativeHandle(); diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h index dbd7c47..5b6be90 100644 --- a/chrome/browser/notifications/balloon_host.h +++ b/chrome/browser/notifications/balloon_host.h @@ -103,6 +103,8 @@ class BalloonHost : public RenderViewHostDelegate, virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} virtual void GotFocus() {} virtual void TakeFocus(bool reverse) {} + virtual void Activate() {} + virtual void Deactivate() {} virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { return false; diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 5fa612e..b957d28 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1766,6 +1766,18 @@ void RenderViewHost::OnMsgFocusedNodeChanged() { delegate_->FocusedNodeChanged(); } +void RenderViewHost::OnMsgFocus() { + RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); + if (view) + view->Activate(); +} + +void RenderViewHost::OnMsgBlur() { + RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); + if (view) + view->Deactivate(); +} + gfx::Rect RenderViewHost::GetRootWindowResizerRect() const { return delegate_->GetRootWindowResizerRect(); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 10a86b4..b47bb57 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -481,6 +481,8 @@ class RenderViewHost : public RenderWidgetHost { virtual void NotifyRendererUnresponsive(); virtual void NotifyRendererResponsive(); virtual void OnMsgFocusedNodeChanged(); + virtual void OnMsgFocus(); + virtual void OnMsgBlur(); // IPC message handlers. void OnMsgShowView(int route_id, diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 4d28c3b..0be5784 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -153,10 +153,16 @@ class RenderViewHostDelegate { // Notification that view for this delegate got the focus. virtual void GotFocus() = 0; - // Callback to inform the browser it should take back focus. If reverse is - // true, it means the focus was retrieved by doing a Shift-Tab. + // Callback to inform the browser that the page is returning the focus to + // the browser's chrome. If reverse is true, it means the focus was + // retrieved by doing a Shift-Tab. virtual void TakeFocus(bool reverse) = 0; + // The page wants the hosting window to activate/deactivate itself (it + // called the JavaScript window.focus()/blur() method). + virtual void Activate() = 0; + virtual void Deactivate() = 0; + // Callback to give the browser a chance to handle the specified keyboard // event before sending it to the renderer. // Returns true if the |event| was handled. Otherwise, if the |event| would diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc index 5cb889c..53427ef 100644 --- a/chrome/browser/renderer_host/render_widget_host.cc +++ b/chrome/browser/renderer_host/render_widget_host.cc @@ -882,14 +882,13 @@ void RenderWidgetHost::ProcessWheelAck() { } void RenderWidgetHost::OnMsgFocus() { - // Only the user can focus a RenderWidgetHost. + // Only RenderViewHost can deal with that message. process()->ReceivedBadMessage(ViewHostMsg_Focus__ID); } void RenderWidgetHost::OnMsgBlur() { - if (view_) { - view_->Blur(); - } + // Only RenderViewHost can deal with that message. + process()->ReceivedBadMessage(ViewHostMsg_Blur__ID); } void RenderWidgetHost::OnMsgSetCursor(const WebCursor& cursor) { diff --git a/chrome/browser/renderer_host/render_widget_host.h b/chrome/browser/renderer_host/render_widget_host.h index d729cba..2f31158 100644 --- a/chrome/browser/renderer_host/render_widget_host.h +++ b/chrome/browser/renderer_host/render_widget_host.h @@ -481,8 +481,8 @@ class RenderWidgetHost : public IPC::Channel::Listener, void OnMsgUpdateVideo(TransportDIB::Id bitmap, const gfx::Rect& bitmap_rect); void OnMsgDestroyVideo(); void OnMsgInputEventAck(const IPC::Message& message); - void OnMsgFocus(); - void OnMsgBlur(); + virtual void OnMsgFocus(); + virtual void OnMsgBlur(); void OnMsgSetCursor(const WebCursor& cursor); void OnMsgImeUpdateTextInputState(WebKit::WebTextInputType type, diff --git a/chrome/browser/tab_contents/background_contents.h b/chrome/browser/tab_contents/background_contents.h index d4fe7ea..3c81345 100644 --- a/chrome/browser/tab_contents/background_contents.h +++ b/chrome/browser/tab_contents/background_contents.h @@ -83,6 +83,8 @@ class BackgroundContents : public RenderViewHostDelegate, virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} virtual void GotFocus() {} virtual void TakeFocus(bool reverse) {} + virtual void Activate() {} + virtual void Deactivate() {} virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { return false; diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index b5c7c39..4f422fb 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -108,6 +108,8 @@ class InterstitialPage::InterstitialPageRVHViewDelegate virtual void UpdateDragCursor(WebDragOperation operation); virtual void GotFocus(); virtual void TakeFocus(bool reverse); + virtual void Activate(); + virtual void Deactivate(); virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut); virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); @@ -610,6 +612,16 @@ void InterstitialPage::InterstitialPageRVHViewDelegate::TakeFocus( interstitial_page_->tab()->GetViewDelegate()->TakeFocus(reverse); } +void InterstitialPage::InterstitialPageRVHViewDelegate::Activate() { + if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) + interstitial_page_->tab()->GetViewDelegate()->Activate(); +} + +void InterstitialPage::InterstitialPageRVHViewDelegate::Deactivate() { + if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) + interstitial_page_->tab()->GetViewDelegate()->Deactivate(); +} + bool InterstitialPage::InterstitialPageRVHViewDelegate::PreHandleKeyboardEvent( const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) diff --git a/chrome/browser/tab_contents/tab_contents_delegate.cc b/chrome/browser/tab_contents/tab_contents_delegate.cc index 9c89cd3..18d2bfc 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.cc +++ b/chrome/browser/tab_contents/tab_contents_delegate.cc @@ -70,6 +70,12 @@ bool TabContentsDelegate::TakeFocus(bool reverse) { return false; } +void TabContentsDelegate::Activate() { +} + +void TabContentsDelegate::Deactivate(){ +} + void TabContentsDelegate::SetTabContentBlocked( TabContents* contents, bool blocked) { } diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index a6b2597..c01db78 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -175,11 +175,16 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { RenderViewHost* render_view_host, const std::string& extension_id); - // This is called when webkit tells us that it is done tabbing through + // This is called when WebKit tells us that it is done tabbing through // controls on the page. Provides a way for TabContentsDelegates to handle // this. Returns true if the delegate successfully handled it. virtual bool TakeFocus(bool reverse); + // Called by WebKit to notify that the page requested the tab hosting window + // to be activated/deactivated (by calling window.focus()/blur()). + virtual void Activate(); + virtual void Deactivate(); + // Changes the blocked state of the tab at |index|. TabContents are // considered blocked while displaying a tab modal dialog. During that time // renderer host will ignore any UI interaction within TabContent outside of diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index 00eaed76..7ce6ed0 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -66,6 +66,14 @@ void TabContentsView::ShowCreatedWidget(int route_id, ShowCreatedWidgetInternal(widget_host_view, initial_pos); } +void TabContentsView::Activate() { + tab_contents_->delegate()->Activate(); +} + +void TabContentsView::Deactivate() { + tab_contents_->delegate()->Deactivate(); +} + bool TabContentsView::PreHandleKeyboardEvent( const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { return tab_contents_->delegate() && diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index 3f9532f..82d01f1 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -187,6 +187,8 @@ class TabContentsView : public RenderViewHostDelegate::View { const gfx::Rect& initial_pos, bool user_gesture); virtual void ShowCreatedWidget(int route_id, const gfx::Rect& initial_pos); + virtual void Activate(); + virtual void Deactivate(); // The TabContents whose contents we display. TabContents* tab_contents_; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 8c1189c..0174537 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -762,6 +762,10 @@ void BrowserView::Activate() { frame_->GetWindow()->Activate(); } +void BrowserView::Deactivate() { + frame_->GetWindow()->Deactivate(); +} + bool BrowserView::IsActive() const { return frame_->GetWindow()->IsActive(); } diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index d2cadda..62c628c 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -244,6 +244,7 @@ class BrowserView : public BrowserBubbleHost, virtual void SetBounds(const gfx::Rect& bounds); virtual void Close(); virtual void Activate(); + virtual void Deactivate(); virtual bool IsActive() const; virtual void FlashFrame(); virtual gfx::NativeWindow GetNativeHandle(); diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index a5f3c0b..0ca11f1 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -628,13 +628,7 @@ void RenderWidget::show(WebNavigationPolicy) { } void RenderWidget::didFocus() { - // Prevent the widget from stealing the focus if it does not have focus - // already. We do this by explicitely setting the focus to false again. - // We only let the browser focus the renderer. - if (!has_focus_ && webwidget_) { - MessageLoop::current()->PostTask(FROM_HERE, - NewRunnableMethod(this, &RenderWidget::ClearFocus)); - } + Send(new ViewHostMsg_Focus(routing_id_)); } void RenderWidget::didBlur() { diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index 5cfbd0b..878bf72 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -23,6 +23,7 @@ class TestBrowserWindow : public BrowserWindow { virtual void SetBounds(const gfx::Rect& bounds) {} virtual void Close() {} virtual void Activate() {} + virtual void Deactivate() {} virtual bool IsActive() const { return false; } virtual void FlashFrame() {} virtual gfx::NativeWindow GetNativeHandle() { return NULL; } diff --git a/views/window/window.h b/views/window/window.h index af1dc70..1d5ffea 100644 --- a/views/window/window.h +++ b/views/window/window.h @@ -93,9 +93,13 @@ class Window { virtual void DisableInactiveRendering() = 0; #endif - // Activate the window, assuming it already exists and is visible. + // Activates the window, assuming it already exists and is visible. virtual void Activate() = 0; + // Deactivates the window, making the next window in the Z order the active + // window. + virtual void Deactivate() = 0; + // Closes the window, ultimately destroying it. This isn't immediate (it // occurs after a return to the message loop. Implementors must also make sure // that invoking Close multiple times doesn't cause bad things to happen, diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index f4d00f7..b22aa9a 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -130,6 +130,10 @@ void WindowGtk::Activate() { gtk_window_present(GTK_WINDOW(GetNativeView())); } +void WindowGtk::Deactivate() { + // TODO(jcivelli): http://crbug.com/51364 Implement me. +} + void WindowGtk::Close() { if (window_closed_) { // Don't do anything if we've already been closed. diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h index c62bc71..b184979 100644 --- a/views/window/window_gtk.h +++ b/views/window/window_gtk.h @@ -33,6 +33,7 @@ class WindowGtk : public WidgetGtk, public Window { virtual void Show(); virtual void HideWindow(); virtual void Activate(); + virtual void Deactivate(); virtual void Close(); virtual void Maximize(); virtual void Minimize(); diff --git a/views/window/window_win.cc b/views/window/window_win.cc index ac347f5..af03463 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -244,6 +244,12 @@ void WindowWin::Activate() { SetForegroundWindow(GetNativeView()); } +void WindowWin::Deactivate() { + HWND hwnd = ::GetNextWindow(GetNativeView(), GW_HWNDNEXT); + if (hwnd) + ::SetForegroundWindow(hwnd); +} + void WindowWin::Close() { if (window_closed_) { // It appears we can hit this code path if you close a modal dialog then diff --git a/views/window/window_win.h b/views/window/window_win.h index eb6ba63..60210f9 100644 --- a/views/window/window_win.h +++ b/views/window/window_win.h @@ -65,6 +65,7 @@ class WindowWin : public WidgetWin, virtual void PushForceHidden(); virtual void PopForceHidden(); virtual void Activate(); + virtual void Deactivate(); virtual void Close(); virtual void Maximize(); virtual void Minimize(); @@ -156,7 +157,7 @@ class WindowWin : public WidgetWin, RECT window_rect; }; - // Set the window as modal (by disabling all the other windows). + // Sets the window as modal (by disabling all the other windows). void BecomeModal(); // Sets-up the focus manager with the view that should have focus when the |