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/browser_frame_aura.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
10 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h" | 10 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h" |
11 #include "grit/chromium_strings.h" | 11 #include "grit/chromium_strings.h" |
12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
13 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
16 #include "ui/base/hit_test.h" | 16 #include "ui/base/hit_test.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/models/simple_menu_model.h" | 18 #include "ui/base/models/simple_menu_model.h" |
19 #include "ui/gfx/font.h" | 19 #include "ui/gfx/font.h" |
20 #include "ui/views/controls/menu/menu_model_adapter.h" | 20 #include "ui/views/controls/menu/menu_model_adapter.h" |
21 #include "ui/views/controls/menu/menu_runner.h" | 21 #include "ui/views/controls/menu/menu_runner.h" |
22 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
23 | 23 |
24 #if defined(USE_ASH) | 24 #if defined(USE_ASH) |
25 #include "ash/wm/property_util.h" | 25 #include "ash/wm/property_util.h" |
| 26 #include "ash/wm/window_util.h" |
26 #endif | 27 #endif |
27 | 28 |
28 #if !defined(OS_CHROMEOS) | 29 #if !defined(OS_CHROMEOS) |
29 #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h" | 30 #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h" |
30 #endif | 31 #endif |
31 | 32 |
32 using aura::Window; | 33 using aura::Window; |
33 | 34 |
34 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
35 // BrowserFrameAura::WindowPropertyWatcher | 36 // BrowserFrameAura::WindowPropertyWatcher |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 GetNativeWindow()->AddObserver(window_property_watcher_.get()); | 103 GetNativeWindow()->AddObserver(window_property_watcher_.get()); |
103 #if defined(USE_ASH) | 104 #if defined(USE_ASH) |
104 // Tabbed browsers and apps (some apps are TYPE_POPUP) get their own | 105 // Tabbed browsers and apps (some apps are TYPE_POPUP) get their own |
105 // workspace. | 106 // workspace. |
106 if (browser_view->browser()->type() != Browser::TYPE_POPUP || | 107 if (browser_view->browser()->type() != Browser::TYPE_POPUP || |
107 browser_view->browser()->is_app()) { | 108 browser_view->browser()->is_app()) { |
108 ash::SetPersistsAcrossAllWorkspaces( | 109 ash::SetPersistsAcrossAllWorkspaces( |
109 GetNativeWindow(), | 110 GetNativeWindow(), |
110 ash::WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_NO); | 111 ash::WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_NO); |
111 } | 112 } |
| 113 // Turn on auto window management if we don't need an explicit bounds. |
| 114 // This way the requested bounds are honored. |
| 115 if (!browser_view->browser()->bounds_overridden() && |
| 116 !browser_view->browser()->is_session_restore()) |
| 117 SetWindowAutoManaged(); |
112 #endif | 118 #endif |
113 } | 119 } |
114 | 120 |
115 /////////////////////////////////////////////////////////////////////////////// | 121 /////////////////////////////////////////////////////////////////////////////// |
116 // BrowserFrameAura, views::ContextMenuController overrides: | 122 // BrowserFrameAura, views::ContextMenuController overrides: |
117 void BrowserFrameAura::ShowContextMenuForView(views::View* source, | 123 void BrowserFrameAura::ShowContextMenuForView(views::View* source, |
118 const gfx::Point& p) { | 124 const gfx::Point& p) { |
119 // Only show context menu if point is in unobscured parts of browser, i.e. | 125 // Only show context menu if point is in unobscured parts of browser, i.e. |
120 // if NonClientHitTest returns : | 126 // if NonClientHitTest returns : |
121 // - HTCAPTION: in title bar or unobscured part of tabstrip | 127 // - HTCAPTION: in title bar or unobscured part of tabstrip |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); | 159 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); |
154 views::NativeWidgetAura::OnWindowDestroying(); | 160 views::NativeWidgetAura::OnWindowDestroying(); |
155 } | 161 } |
156 | 162 |
157 void BrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) { | 163 void BrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) { |
158 // On Aura when the BrowserView is shown it tries to restore focus, but can | 164 // On Aura when the BrowserView is shown it tries to restore focus, but can |
159 // be blocked when this parent BrowserFrameAura isn't visible. Therefore we | 165 // be blocked when this parent BrowserFrameAura isn't visible. Therefore we |
160 // RestoreFocus() when we become visible, which results in the web contents | 166 // RestoreFocus() when we become visible, which results in the web contents |
161 // being asked to focus, which places focus either in the web contents or in | 167 // being asked to focus, which places focus either in the web contents or in |
162 // the location bar as appropriate. | 168 // the location bar as appropriate. |
163 if (visible) | 169 if (visible) { |
| 170 // Once the window has been shown we know the requested bounds |
| 171 // (if provided) have been honored and we can switch on window management. |
| 172 SetWindowAutoManaged(); |
| 173 |
164 browser_view_->RestoreFocus(); | 174 browser_view_->RestoreFocus(); |
| 175 } |
165 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); | 176 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); |
166 } | 177 } |
167 | 178 |
168 //////////////////////////////////////////////////////////////////////////////// | 179 //////////////////////////////////////////////////////////////////////////////// |
169 // BrowserFrameAura, NativeBrowserFrame implementation: | 180 // BrowserFrameAura, NativeBrowserFrame implementation: |
170 | 181 |
171 views::NativeWidget* BrowserFrameAura::AsNativeWidget() { | 182 views::NativeWidget* BrowserFrameAura::AsNativeWidget() { |
172 return this; | 183 return this; |
173 } | 184 } |
174 | 185 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 return new DesktopBrowserFrameAura(browser_frame, browser_view); | 223 return new DesktopBrowserFrameAura(browser_frame, browser_view); |
213 #endif | 224 #endif |
214 return new BrowserFrameAura(browser_frame, browser_view); | 225 return new BrowserFrameAura(browser_frame, browser_view); |
215 } | 226 } |
216 | 227 |
217 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
218 // BrowserFrameAura, private: | 229 // BrowserFrameAura, private: |
219 | 230 |
220 BrowserFrameAura::~BrowserFrameAura() { | 231 BrowserFrameAura::~BrowserFrameAura() { |
221 } | 232 } |
| 233 |
| 234 void BrowserFrameAura::SetWindowAutoManaged() { |
| 235 #if defined(USE_ASH) |
| 236 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || |
| 237 browser_view_->browser()->is_app()) |
| 238 ash::wm::SetWindowPositionManaged(GetNativeWindow(), true); |
| 239 #endif |
| 240 } |
OLD | NEW |