OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_aur
a.h" |
| 6 |
| 7 #include "chrome/browser/ui/view_ids.h" |
| 8 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" |
| 9 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_view_win.h" |
| 11 #include "content/browser/tab_contents/interstitial_page.h" |
| 12 #include "content/browser/tab_contents/tab_contents.h" |
| 13 #include "ui/base/accessibility/accessible_view_state.h" |
| 14 #include "views/views_delegate.h" |
| 15 #include "views/focus/focus_manager.h" |
| 16 |
| 17 //////////////////////////////////////////////////////////////////////////////// |
| 18 // NativeTabContentsContainerAura, public: |
| 19 |
| 20 NativeTabContentsContainerAura::NativeTabContentsContainerAura( |
| 21 TabContentsContainer* container) |
| 22 : container_(container) { |
| 23 set_id(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); |
| 24 } |
| 25 |
| 26 NativeTabContentsContainerAura::~NativeTabContentsContainerAura() { |
| 27 } |
| 28 |
| 29 //////////////////////////////////////////////////////////////////////////////// |
| 30 // NativeTabContentsContainerAura, NativeTabContentsContainer overrides: |
| 31 |
| 32 void NativeTabContentsContainerAura::AttachContents(TabContents* contents) { |
| 33 // We need to register the tab contents window with the BrowserContainer so |
| 34 // that the BrowserContainer is the focused view when the focus is on the |
| 35 // TabContents window (for the TabContents case). |
| 36 set_focus_view(this); |
| 37 |
| 38 Attach(contents->GetNativeView()); |
| 39 } |
| 40 |
| 41 void NativeTabContentsContainerAura::DetachContents(TabContents* contents) { |
| 42 // Detach the TabContents. Do this before we unparent the |
| 43 // TabContentsViewViews so that the window hierarchy is intact for any |
| 44 // cleanup during Detach(). |
| 45 Detach(); |
| 46 |
| 47 #if !defined(USE_AURA) |
| 48 // TODO(brettw) should this move to NativeViewHost::Detach? It |
| 49 // needs cleanup regardless. |
| 50 HWND container_hwnd = contents->GetNativeView(); |
| 51 if (container_hwnd) { |
| 52 // Hide the contents before adjusting its parent to avoid a full desktop |
| 53 // flicker. |
| 54 ShowWindow(container_hwnd, SW_HIDE); |
| 55 |
| 56 // Reset the parent to NULL to ensure hidden tabs don't receive messages. |
| 57 static_cast<TabContentsViewViews*>(contents->view())->Unparent(); |
| 58 } |
| 59 #else |
| 60 // TODO(beng): |
| 61 NOTIMPLEMENTED(); |
| 62 #endif |
| 63 } |
| 64 |
| 65 void NativeTabContentsContainerAura::SetFastResize(bool fast_resize) { |
| 66 set_fast_resize(fast_resize); |
| 67 } |
| 68 |
| 69 void NativeTabContentsContainerAura::RenderViewHostChanged( |
| 70 RenderViewHost* old_host, |
| 71 RenderViewHost* new_host) { |
| 72 // If we are focused, we need to pass the focus to the new RenderViewHost. |
| 73 if (GetFocusManager()->GetFocusedView() == this) |
| 74 OnFocus(); |
| 75 } |
| 76 |
| 77 views::View* NativeTabContentsContainerAura::GetView() { |
| 78 return this; |
| 79 } |
| 80 |
| 81 void NativeTabContentsContainerAura::TabContentsFocused( |
| 82 TabContents* tab_contents) { |
| 83 views::FocusManager* focus_manager = GetFocusManager(); |
| 84 if (!focus_manager) { |
| 85 NOTREACHED(); |
| 86 return; |
| 87 } |
| 88 focus_manager->SetFocusedView(this); |
| 89 } |
| 90 |
| 91 //////////////////////////////////////////////////////////////////////////////// |
| 92 // NativeTabContentsContainerAura, views::View overrides: |
| 93 |
| 94 bool NativeTabContentsContainerAura::SkipDefaultKeyEventProcessing( |
| 95 const views::KeyEvent& e) { |
| 96 // Don't look-up accelerators or tab-traversal if we are showing a non-crashed |
| 97 // TabContents. |
| 98 // We'll first give the page a chance to process the key events. If it does |
| 99 // not process them, they'll be returned to us and we'll treat them as |
| 100 // accelerators then. |
| 101 return container_->tab_contents() && |
| 102 !container_->tab_contents()->is_crashed(); |
| 103 } |
| 104 |
| 105 bool NativeTabContentsContainerAura::IsFocusable() const { |
| 106 // We need to be focusable when our contents is not a view hierarchy, as |
| 107 // clicking on the contents needs to focus us. |
| 108 return container_->tab_contents() != NULL; |
| 109 } |
| 110 |
| 111 void NativeTabContentsContainerAura::OnFocus() { |
| 112 if (container_->tab_contents()) |
| 113 container_->tab_contents()->Focus(); |
| 114 } |
| 115 |
| 116 void NativeTabContentsContainerAura::RequestFocus() { |
| 117 // This is a hack to circumvent the fact that a the OnFocus() method is not |
| 118 // invoked when RequestFocus() is called on an already focused view. |
| 119 // The TabContentsContainer is the view focused when the TabContents has |
| 120 // focus. When switching between from one tab that has focus to another tab |
| 121 // that should also have focus, RequestFocus() is invoked one the |
| 122 // TabContentsContainer. In order to make sure OnFocus() is invoked we need |
| 123 // to clear the focus before hands. |
| 124 { |
| 125 // Disable notifications. Clear focus will assign the focus to the main |
| 126 // browser window. Because this change of focus was not user requested, |
| 127 // don't send it to listeners. |
| 128 views::AutoNativeNotificationDisabler local_notification_disabler; |
| 129 GetFocusManager()->ClearFocus(); |
| 130 } |
| 131 View::RequestFocus(); |
| 132 } |
| 133 |
| 134 void NativeTabContentsContainerAura::AboutToRequestFocusFromTabTraversal( |
| 135 bool reverse) { |
| 136 container_->tab_contents()->FocusThroughTabTraversal(reverse); |
| 137 } |
| 138 |
| 139 void NativeTabContentsContainerAura::GetAccessibleState( |
| 140 ui::AccessibleViewState* state) { |
| 141 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
| 142 } |
| 143 |
| 144 gfx::NativeViewAccessible |
| 145 NativeTabContentsContainerAura::GetNativeViewAccessible() { |
| 146 TabContents* tab_contents = container_->tab_contents(); |
| 147 if (tab_contents) { |
| 148 #if !defined(USE_AURA) |
| 149 RenderWidgetHostViewWin* host_view_win = |
| 150 static_cast<RenderWidgetHostViewWin*>( |
| 151 tab_contents->GetRenderWidgetHostView()); |
| 152 if (host_view_win) |
| 153 return host_view_win->GetIAccessible(); |
| 154 #else |
| 155 // TODO(beng): |
| 156 NOTIMPLEMENTED(); |
| 157 #endif |
| 158 } |
| 159 |
| 160 return View::GetNativeViewAccessible(); |
| 161 } |
| 162 |
| 163 //////////////////////////////////////////////////////////////////////////////// |
| 164 // NativeTabContentsContainer, public: |
| 165 |
| 166 // static |
| 167 NativeTabContentsContainer* NativeTabContentsContainer::CreateNativeContainer( |
| 168 TabContentsContainer* container) { |
| 169 return new NativeTabContentsContainerAura(container); |
| 170 } |
OLD | NEW |