| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/frame/browser_frame_aura.h" | 5 #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/ui/views/frame/browser_view.h" | 8 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 9 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h" | 9 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h" |
| 10 #include "grit/chromium_strings.h" | 10 #include "grit/chromium_strings.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "ui/aura/client/aura_constants.h" | 12 #include "ui/aura/client/aura_constants.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_observer.h" | 14 #include "ui/aura/window_observer.h" |
| 15 #include "ui/base/hit_test.h" | 15 #include "ui/base/hit_test.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/models/simple_menu_model.h" | 17 #include "ui/base/models/simple_menu_model.h" |
| 18 #include "ui/gfx/font.h" | 18 #include "ui/gfx/font.h" |
| 19 #include "ui/views/controls/menu/menu_model_adapter.h" | 19 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 20 #include "ui/views/controls/menu/menu_runner.h" | 20 #include "ui/views/controls/menu/menu_runner.h" |
| 21 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 22 | 22 |
| 23 #if defined(USE_ASH) | 23 #if defined(USE_ASH) |
| 24 #include "ash/wm/property_util.h" | 24 #include "ash/wm/property_util.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 using aura::Window; | 27 using aura::Window; |
| 28 | 28 |
| 29 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 30 // BrowserFrameAura::WindowPropertyWatcher | 30 // DesktopBrowserFrameAura::WindowPropertyWatcher |
| 31 | 31 |
| 32 class BrowserFrameAura::WindowPropertyWatcher : public aura::WindowObserver { | 32 class DesktopBrowserFrameAura::WindowPropertyWatcher |
| 33 : public aura::WindowObserver { |
| 33 public: | 34 public: |
| 34 explicit WindowPropertyWatcher(BrowserFrameAura* browser_frame_aura, | 35 explicit WindowPropertyWatcher(DesktopBrowserFrameAura* browser_frame_aura, |
| 35 BrowserFrame* browser_frame) | 36 BrowserFrame* browser_frame) |
| 36 : browser_frame_aura_(browser_frame_aura), | 37 : browser_frame_aura_(browser_frame_aura), |
| 37 browser_frame_(browser_frame) {} | 38 browser_frame_(browser_frame) {} |
| 38 | 39 |
| 39 virtual void OnWindowPropertyChanged(aura::Window* window, | 40 virtual void OnWindowPropertyChanged(aura::Window* window, |
| 40 const void* key, | 41 const void* key, |
| 41 intptr_t old) OVERRIDE { | 42 intptr_t old) OVERRIDE { |
| 42 if (key != aura::client::kShowStateKey) | 43 if (key != aura::client::kShowStateKey) |
| 43 return; | 44 return; |
| 44 | 45 |
| 45 // Allow the frame to be replaced when maximizing an app. | 46 // Allow the frame to be replaced when maximizing an app. |
| 46 if (browser_frame_->non_client_view() && | 47 if (browser_frame_->non_client_view() && |
| 47 browser_frame_aura_->browser_view()->browser()->is_app()) | 48 browser_frame_aura_->browser_view()->browser()->is_app()) |
| 48 browser_frame_->non_client_view()->UpdateFrame(); | 49 browser_frame_->non_client_view()->UpdateFrame(false); |
| 49 } | 50 } |
| 50 | 51 |
| 51 virtual void OnWindowBoundsChanged(aura::Window* window, | 52 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 52 const gfx::Rect& old_bounds, | 53 const gfx::Rect& old_bounds, |
| 53 const gfx::Rect& new_bounds) OVERRIDE { | 54 const gfx::Rect& new_bounds) OVERRIDE { |
| 54 // Don't do anything if we don't have our non-client view yet. | 55 // Don't do anything if we don't have our non-client view yet. |
| 55 if (!browser_frame_->non_client_view()) | 56 if (!browser_frame_->non_client_view()) |
| 56 return; | 57 return; |
| 57 | 58 |
| 58 // If the window just moved to the top of the screen, or just moved away | 59 // If the window just moved to the top of the screen, or just moved away |
| 59 // from it, invoke Layout() so the header size can change. | 60 // from it, invoke Layout() so the header size can change. |
| 60 if ((old_bounds.y() == 0 && new_bounds.y() != 0) || | 61 if ((old_bounds.y() == 0 && new_bounds.y() != 0) || |
| 61 (old_bounds.y() != 0 && new_bounds.y() == 0)) | 62 (old_bounds.y() != 0 && new_bounds.y() == 0)) |
| 62 browser_frame_->non_client_view()->Layout(); | 63 browser_frame_->non_client_view()->Layout(); |
| 63 } | 64 } |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 BrowserFrameAura* browser_frame_aura_; | 67 DesktopBrowserFrameAura* browser_frame_aura_; |
| 67 BrowserFrame* browser_frame_; | 68 BrowserFrame* browser_frame_; |
| 68 | 69 |
| 69 DISALLOW_COPY_AND_ASSIGN(WindowPropertyWatcher); | 70 DISALLOW_COPY_AND_ASSIGN(WindowPropertyWatcher); |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 /////////////////////////////////////////////////////////////////////////////// | 73 /////////////////////////////////////////////////////////////////////////////// |
| 73 // BrowserFrameAura, public: | 74 // DesktopBrowserFrameAura, public: |
| 74 | 75 |
| 75 BrowserFrameAura::BrowserFrameAura(BrowserFrame* browser_frame, | 76 DesktopBrowserFrameAura::DesktopBrowserFrameAura( |
| 76 BrowserView* browser_view) | 77 BrowserFrame* browser_frame, |
| 77 : views::NativeWidgetAura(browser_frame), | 78 BrowserView* browser_view) |
| 79 : views::DesktopNativeWidgetAura(browser_frame), |
| 78 browser_view_(browser_view), | 80 browser_view_(browser_view), |
| 79 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { | 81 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { |
| 80 GetNativeWindow()->SetName("BrowserFrameAura"); | 82 GetNativeWindow()->SetName("BrowserFrameAura"); |
| 81 GetNativeWindow()->AddObserver(window_property_watcher_.get()); | 83 GetNativeWindow()->AddObserver(window_property_watcher_.get()); |
| 82 #if defined(USE_ASH) | 84 #if defined(USE_ASH) |
| 83 if (browser_view->browser()->type() != Browser::TYPE_POPUP) { | 85 if (browser_view->browser()->type() != Browser::TYPE_POPUP) { |
| 84 ash::SetPersistsAcrossAllWorkspaces( | 86 ash::SetPersistsAcrossAllWorkspaces( |
| 85 GetNativeWindow(), | 87 GetNativeWindow(), |
| 86 ash::WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_NO); | 88 ash::WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_NO); |
| 87 } | 89 } |
| 88 // HACK: Don't animate app windows. They delete and rebuild their frame on | 90 // HACK: Don't animate app windows. They delete and rebuild their frame on |
| 89 // maximize, which breaks the layer animations. We probably shouldn't rebuild | 91 // maximize, which breaks the layer animations. We probably shouldn't rebuild |
| 90 // the frame view on this transition. | 92 // the frame view on this transition. |
| 91 // TODO(jamescook): Fix app window animation. http://crbug.com/131293 | 93 // TODO(jamescook): Fix app window animation. http://crbug.com/131293 |
| 92 if (browser_view->browser()->is_app()) { | 94 if (browser_view->browser()->is_app()) { |
| 93 Window* window = GetNativeWindow(); | 95 Window* window = GetNativeWindow(); |
| 94 window->SetProperty(aura::client::kAnimationsDisabledKey, true); | 96 window->SetProperty(aura::client::kAnimationsDisabledKey, true); |
| 95 } | 97 } |
| 96 #endif | 98 #endif |
| 97 } | 99 } |
| 98 | 100 |
| 99 /////////////////////////////////////////////////////////////////////////////// | 101 /////////////////////////////////////////////////////////////////////////////// |
| 100 // BrowserFrameAura, views::ContextMenuController overrides: | 102 // DesktopBrowserFrameAura, views::ContextMenuController overrides: |
| 101 void BrowserFrameAura::ShowContextMenuForView(views::View* source, | 103 void DesktopBrowserFrameAura::ShowContextMenuForView(views::View* source, |
| 102 const gfx::Point& p) { | 104 const gfx::Point& p) { |
| 103 // Only show context menu if point is in unobscured parts of browser, i.e. | 105 // Only show context menu if point is in unobscured parts of browser, i.e. |
| 104 // if NonClientHitTest returns : | 106 // if NonClientHitTest returns : |
| 105 // - HTCAPTION: in title bar or unobscured part of tabstrip | 107 // - HTCAPTION: in title bar or unobscured part of tabstrip |
| 106 // - HTNOWHERE: as the name implies. | 108 // - HTNOWHERE: as the name implies. |
| 107 views::NonClientView* non_client_view = browser_view()->frame()-> | 109 views::NonClientView* non_client_view = browser_view()->frame()-> |
| 108 non_client_view(); | 110 non_client_view(); |
| 109 gfx::Point point_in_view_coords(p); | 111 gfx::Point point_in_view_coords(p); |
| 110 views::View::ConvertPointFromScreen(non_client_view, &point_in_view_coords); | 112 views::View::ConvertPointFromScreen(non_client_view, &point_in_view_coords); |
| 111 int hit_test = non_client_view->NonClientHitTest(point_in_view_coords); | 113 int hit_test = non_client_view->NonClientHitTest(point_in_view_coords); |
| 112 if (hit_test == HTCAPTION || hit_test == HTNOWHERE) { | 114 if (hit_test == HTCAPTION || hit_test == HTNOWHERE) { |
| 113 SystemMenuModelDelegate menu_delegate(browser_view(), | 115 SystemMenuModelDelegate menu_delegate(browser_view(), |
| 114 browser_view()->browser()); | 116 browser_view()->browser()); |
| 115 ui::SimpleMenuModel model(&menu_delegate); | 117 ui::SimpleMenuModel model(&menu_delegate); |
| 116 model.AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); | 118 model.AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); |
| 117 model.AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); | 119 model.AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); |
| 118 model.AddSeparator(ui::NORMAL_SEPARATOR); | 120 model.AddSeparator(ui::NORMAL_SEPARATOR); |
| 119 model.AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); | 121 model.AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
| 120 views::MenuModelAdapter menu_adapter(&model); | 122 views::MenuModelAdapter menu_adapter(&model); |
| 121 menu_runner_.reset(new views::MenuRunner(menu_adapter.CreateMenu())); | 123 menu_runner_.reset(new views::MenuRunner(menu_adapter.CreateMenu())); |
| 122 | 124 |
| 123 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL, | 125 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL, |
| 124 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT, | 126 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT, |
| 125 views::MenuRunner::HAS_MNEMONICS) == | 127 views::MenuRunner::HAS_MNEMONICS) == |
| 126 views::MenuRunner::MENU_DELETED) | 128 views::MenuRunner::MENU_DELETED) |
| 127 return; | 129 return; |
| 128 } | 130 } |
| 129 } | 131 } |
| 130 | 132 |
| 131 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
| 132 // BrowserFrameAura, views::NativeWidgetAura overrides: | 134 // DesktopBrowserFrameAura, views::DestkopNativeWidgetAura overrides: |
| 133 | 135 |
| 134 void BrowserFrameAura::OnWindowDestroying() { | 136 void DesktopBrowserFrameAura::OnWindowDestroying() { |
| 135 // Window is destroyed before our destructor is called, so clean up our | 137 // Window is destroyed before our destructor is called, so clean up our |
| 136 // observer here. | 138 // observer here. |
| 137 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); | 139 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); |
| 138 views::NativeWidgetAura::OnWindowDestroying(); | 140 views::DesktopNativeWidgetAura::OnWindowDestroying(); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void BrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) { | 143 void DesktopBrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) { |
| 142 // On Aura when the BrowserView is shown it tries to restore focus, but can | 144 // On Aura when the BrowserView is shown it tries to restore focus, but can |
| 143 // be blocked when this parent BrowserFrameAura isn't visible. Therefore we | 145 // be blocked when this parent BrowserFrameAura isn't visible. Therefore we |
| 144 // RestoreFocus() when we become visible, which results in the web contents | 146 // RestoreFocus() when we become visible, which results in the web contents |
| 145 // being asked to focus, which places focus either in the web contents or in | 147 // being asked to focus, which places focus either in the web contents or in |
| 146 // the location bar as appropriate. | 148 // the location bar as appropriate. |
| 147 if (visible) | 149 if (visible) |
| 148 browser_view_->RestoreFocus(); | 150 browser_view_->RestoreFocus(); |
| 149 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); | 151 views::DesktopNativeWidgetAura::OnWindowTargetVisibilityChanged(visible); |
| 150 } | 152 } |
| 151 | 153 |
| 152 //////////////////////////////////////////////////////////////////////////////// | 154 //////////////////////////////////////////////////////////////////////////////// |
| 153 // BrowserFrameAura, NativeBrowserFrame implementation: | 155 // DesktopBrowserFrameAura, NativeBrowserFrame implementation: |
| 154 | 156 |
| 155 views::NativeWidget* BrowserFrameAura::AsNativeWidget() { | 157 views::NativeWidget* DesktopBrowserFrameAura::AsNativeWidget() { |
| 156 return this; | 158 return this; |
| 157 } | 159 } |
| 158 | 160 |
| 159 const views::NativeWidget* BrowserFrameAura::AsNativeWidget() const { | 161 const views::NativeWidget* DesktopBrowserFrameAura::AsNativeWidget() const { |
| 160 return this; | 162 return this; |
| 161 } | 163 } |
| 162 | 164 |
| 163 void BrowserFrameAura::InitSystemContextMenu() { | 165 void DesktopBrowserFrameAura::InitSystemContextMenu() { |
| 164 views::NonClientView* non_client_view = | 166 views::NonClientView* non_client_view = |
| 165 browser_view()->frame()->non_client_view(); | 167 browser_view()->frame()->non_client_view(); |
| 166 DCHECK(non_client_view); | 168 DCHECK(non_client_view); |
| 167 non_client_view->set_context_menu_controller(this); | 169 non_client_view->set_context_menu_controller(this); |
| 168 } | 170 } |
| 169 | 171 |
| 170 int BrowserFrameAura::GetMinimizeButtonOffset() const { | 172 int DesktopBrowserFrameAura::GetMinimizeButtonOffset() const { |
| 171 return 0; | 173 return 0; |
| 172 } | 174 } |
| 173 | 175 |
| 174 void BrowserFrameAura::TabStripDisplayModeChanged() { | 176 void DesktopBrowserFrameAura::TabStripDisplayModeChanged() { |
| 175 } | |
| 176 | |
| 177 //////////////////////////////////////////////////////////////////////////////// | |
| 178 // BrowserFrame, public: | |
| 179 | |
| 180 // static | |
| 181 const gfx::Font& BrowserFrame::GetTitleFont() { | |
| 182 static gfx::Font* title_font = new gfx::Font; | |
| 183 return *title_font; | |
| 184 } | |
| 185 | |
| 186 //////////////////////////////////////////////////////////////////////////////// | |
| 187 // NativeBrowserFrame, public: | |
| 188 | |
| 189 // static | |
| 190 NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( | |
| 191 BrowserFrame* browser_frame, | |
| 192 BrowserView* browser_view) { | |
| 193 return new BrowserFrameAura(browser_frame, browser_view); | |
| 194 } | 177 } |
| 195 | 178 |
| 196 /////////////////////////////////////////////////////////////////////////////// | 179 /////////////////////////////////////////////////////////////////////////////// |
| 197 // BrowserFrameAura, private: | 180 // DesktopBrowserFrameAura, private: |
| 198 | 181 |
| 199 BrowserFrameAura::~BrowserFrameAura() { | 182 DesktopBrowserFrameAura::~DesktopBrowserFrameAura() { |
| 200 } | 183 } |
| OLD | NEW |