OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_frame_ash.h" |
6 | 6 |
7 #include "ash/wm/window_state.h" | 7 #include "ash/wm/window_state.h" |
| 8 #include "ash/wm/window_state_delegate.h" |
8 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" |
9 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
10 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
12 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
13 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
14 | 17 |
15 using aura::Window; | 18 using aura::Window; |
16 | 19 |
| 20 namespace { |
| 21 |
| 22 // BrowserWindowStateDelegate classe handles a user's fullscreen |
| 23 // request (Shift+F4/F4) for browser (tabbed/popup) windows. |
| 24 class BrowserWindowStateDelegate : public ash::wm::WindowStateDelegate { |
| 25 public: |
| 26 explicit BrowserWindowStateDelegate(Browser* browser) |
| 27 : browser_(browser) { |
| 28 DCHECK(browser_); |
| 29 } |
| 30 virtual ~BrowserWindowStateDelegate(){} |
| 31 |
| 32 // Overridden from ash::wm::WindowStateDelegate. |
| 33 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { |
| 34 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); |
| 35 // Windows which cannot be maximized should not be fullscreened. |
| 36 if (!window_state->IsFullscreen() && !window_state->CanMaximize()) |
| 37 return true; |
| 38 chrome::ToggleFullscreenMode(browser_); |
| 39 return true; |
| 40 } |
| 41 private: |
| 42 Browser* browser_; // not owned. |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(BrowserWindowStateDelegate); |
| 45 }; |
| 46 |
| 47 // AppNonClientFrameViewAsh shows only the window controls and no |
| 48 // other window decorations which is pretty close to fullscreen. Put |
| 49 // v1 apps into maximized mode instead of fullscreen to avoid showing |
| 50 // the ugly fullscreen exit bubble. This is used for V1 apps. |
| 51 class AppWindowStateDelegate : public ash::wm::WindowStateDelegate { |
| 52 public: |
| 53 explicit AppWindowStateDelegate(Browser* browser) |
| 54 : browser_(browser) { |
| 55 DCHECK(browser_); |
| 56 } |
| 57 virtual ~AppWindowStateDelegate(){} |
| 58 |
| 59 // Overridden from ash::wm::WindowStateDelegate. |
| 60 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { |
| 61 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); |
| 62 if (window_state->IsFullscreen()) |
| 63 chrome::ToggleFullscreenMode(browser_); |
| 64 else |
| 65 window_state->ToggleMaximized(); |
| 66 return true; |
| 67 } |
| 68 |
| 69 private: |
| 70 Browser* browser_; // not owned. |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(AppWindowStateDelegate); |
| 73 }; |
| 74 |
| 75 |
| 76 } // namespace |
| 77 |
17 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
18 // BrowserFrameAsh::WindowPropertyWatcher | 79 // BrowserFrameAsh::WindowPropertyWatcher |
19 | 80 |
20 class BrowserFrameAsh::WindowPropertyWatcher : public aura::WindowObserver { | 81 class BrowserFrameAsh::WindowPropertyWatcher : public aura::WindowObserver { |
21 public: | 82 public: |
22 explicit WindowPropertyWatcher(BrowserFrameAsh* browser_frame_ash, | 83 explicit WindowPropertyWatcher(BrowserFrameAsh* browser_frame_ash, |
23 BrowserFrame* browser_frame) | 84 BrowserFrame* browser_frame) |
24 : browser_frame_ash_(browser_frame_ash), | 85 : browser_frame_ash_(browser_frame_ash), |
25 browser_frame_(browser_frame) {} | 86 browser_frame_(browser_frame) {} |
26 | 87 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // static | 140 // static |
80 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh"; | 141 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh"; |
81 | 142 |
82 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame, | 143 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame, |
83 BrowserView* browser_view) | 144 BrowserView* browser_view) |
84 : views::NativeWidgetAura(browser_frame), | 145 : views::NativeWidgetAura(browser_frame), |
85 browser_view_(browser_view), | 146 browser_view_(browser_view), |
86 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { | 147 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { |
87 GetNativeWindow()->SetName(kWindowName); | 148 GetNativeWindow()->SetName(kWindowName); |
88 GetNativeWindow()->AddObserver(window_property_watcher_.get()); | 149 GetNativeWindow()->AddObserver(window_property_watcher_.get()); |
89 if (browser_view->browser()->is_type_tabbed()) | 150 Browser* browser = browser_view->browser(); |
90 ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false); | 151 ash::wm::WindowState* window_state = |
| 152 ash::wm::GetWindowState(GetNativeWindow()); |
| 153 if (browser->is_app() && browser->app_type() != Browser::APP_TYPE_CHILD) { |
| 154 window_state->SetDelegate( |
| 155 scoped_ptr<ash::wm::WindowStateDelegate>( |
| 156 new AppWindowStateDelegate(browser)).Pass()); |
| 157 } else { |
| 158 window_state->SetDelegate( |
| 159 scoped_ptr<ash::wm::WindowStateDelegate>( |
| 160 new BrowserWindowStateDelegate(browser)).Pass()); |
| 161 } |
| 162 window_state->set_animate_to_fullscreen(!browser->is_type_tabbed()); |
91 | 163 |
92 // Turn on auto window management if we don't need an explicit bounds. | 164 // Turn on auto window management if we don't need an explicit bounds. |
93 // This way the requested bounds are honored. | 165 // This way the requested bounds are honored. |
94 if (!browser_view->browser()->bounds_overridden() && | 166 if (!browser->bounds_overridden() && !browser->is_session_restore()) |
95 !browser_view->browser()->is_session_restore()) | |
96 SetWindowAutoManaged(); | 167 SetWindowAutoManaged(); |
97 #if defined(OS_CHROMEOS) | 168 #if defined(OS_CHROMEOS) |
98 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys | 169 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys |
99 // like brightness, volume, etc. Otherwise these keys are handled by the | 170 // like brightness, volume, etc. Otherwise these keys are handled by the |
100 // Ash window manager. | 171 // Ash window manager. |
101 if (browser_view->browser()->is_app()) { | 172 window_state->set_can_consume_system_keys(browser->is_app()); |
102 ash::wm::GetWindowState(GetNativeWindow())-> | |
103 set_can_consume_system_keys(true); | |
104 } | |
105 #endif // defined(OS_CHROMEOS) | 173 #endif // defined(OS_CHROMEOS) |
106 } | 174 } |
107 | 175 |
108 /////////////////////////////////////////////////////////////////////////////// | 176 /////////////////////////////////////////////////////////////////////////////// |
109 // BrowserFrameAsh, views::NativeWidgetAura overrides: | 177 // BrowserFrameAsh, views::NativeWidgetAura overrides: |
110 | 178 |
111 void BrowserFrameAsh::OnWindowDestroying() { | 179 void BrowserFrameAsh::OnWindowDestroying() { |
112 // Window is destroyed before our destructor is called, so clean up our | 180 // Window is destroyed before our destructor is called, so clean up our |
113 // observer here. | 181 // observer here. |
114 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); | 182 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 BrowserFrameAsh::~BrowserFrameAsh() { | 220 BrowserFrameAsh::~BrowserFrameAsh() { |
153 } | 221 } |
154 | 222 |
155 void BrowserFrameAsh::SetWindowAutoManaged() { | 223 void BrowserFrameAsh::SetWindowAutoManaged() { |
156 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || | 224 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || |
157 browser_view_->browser()->is_app()) { | 225 browser_view_->browser()->is_app()) { |
158 ash::wm::GetWindowState(GetNativeWindow())-> | 226 ash::wm::GetWindowState(GetNativeWindow())-> |
159 set_window_position_managed(true); | 227 set_window_position_managed(true); |
160 } | 228 } |
161 } | 229 } |
OLD | NEW |