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