Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/ui/views/frame/browser_frame_ash.cc

Issue 42353002: Introduce WindowStateDelegate::ToggleFullscreen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
10 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
12 #include "ui/aura/window_observer.h" 16 #include "ui/aura/window_observer.h"
13 #include "ui/views/view.h" 17 #include "ui/views/view.h"
14 18
15 using aura::Window; 19 using aura::Window;
16 20
21 namespace {
22 class BrowserWindowStateDelegate : public ash::wm::WindowStateDelegate {
23 public:
24 BrowserWindowStateDelegate() {}
pkotwicz 2013/10/25 23:31:14 I would much rather have a Browser* parameter be p
oshima 2013/10/28 22:57:51 Done.
25 virtual ~BrowserWindowStateDelegate(){}
26
27 // Invoked when the user uses Shift+F4 to toggle the window fullscreen state.
pkotwicz 2013/10/25 23:31:14 Shift+F4 -> F4
oshima 2013/10/28 22:57:51 Changed to Shift+F4/F4
28 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE {
29 bool is_fullscreen = window_state->IsFullscreen();
30
31 // Windows which cannot be maximized should not be fullscreened.
32 if (!is_fullscreen && !window_state->CanMaximize())
33 return true;
34
35 Browser* browser = chrome::FindBrowserWithWindow(window_state->window());
36 CHECK(browser);
37 if (is_fullscreen) {
38 chrome::ToggleFullscreenMode(browser);
39 return true;
40 }
41 // AppNonClientFrameViewAsh shows only the window controls and no other
pkotwicz 2013/10/25 23:31:14 Would it be possible to set a custom delegate in A
oshima 2013/10/28 22:57:51 Done.
42 // window decorations which is pretty close to fullscreen. Put v1 apps
43 // into maximized mode instead of fullscreen to avoid showing the ugly
44 // fullscreen exit bubble.
45 if (browser->is_app() && browser->app_type() != Browser::APP_TYPE_CHILD)
46 window_state->ToggleMaximized();
47 else
48 chrome::ToggleFullscreenMode(browser);
49 return true;
50 }
51 private:
52 DISALLOW_COPY_AND_ASSIGN(BrowserWindowStateDelegate);
53 };
54
55 } // namespace
56
17 //////////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////////////
18 // BrowserFrameAsh::WindowPropertyWatcher 58 // BrowserFrameAsh::WindowPropertyWatcher
19 59
20 class BrowserFrameAsh::WindowPropertyWatcher : public aura::WindowObserver { 60 class BrowserFrameAsh::WindowPropertyWatcher : public aura::WindowObserver {
21 public: 61 public:
22 explicit WindowPropertyWatcher(BrowserFrameAsh* browser_frame_ash, 62 explicit WindowPropertyWatcher(BrowserFrameAsh* browser_frame_ash,
23 BrowserFrame* browser_frame) 63 BrowserFrame* browser_frame)
24 : browser_frame_ash_(browser_frame_ash), 64 : browser_frame_ash_(browser_frame_ash),
25 browser_frame_(browser_frame) {} 65 browser_frame_(browser_frame) {}
26 66
(...skipping 21 matching lines...) Expand all
48 // an OnBoundsChanged event so that the frame will change its size 88 // an OnBoundsChanged event so that the frame will change its size
49 // properly. 89 // properly.
50 browser_frame_->non_client_view()->UpdateFrame( 90 browser_frame_->non_client_view()->UpdateFrame(
51 old_state == ui::SHOW_STATE_MINIMIZED); 91 old_state == ui::SHOW_STATE_MINIMIZED);
52 } 92 }
53 } 93 }
54 94
55 virtual void OnWindowBoundsChanged(aura::Window* window, 95 virtual void OnWindowBoundsChanged(aura::Window* window,
56 const gfx::Rect& old_bounds, 96 const gfx::Rect& old_bounds,
57 const gfx::Rect& new_bounds) OVERRIDE { 97 const gfx::Rect& new_bounds) OVERRIDE {
58 // Don't do anything if we don't have our non-client view yet. 98 // Don't do anything if we don't have our non-client view yet.
pkotwicz 2013/10/25 23:31:14 Can you do me a favor and remove this method?
pkotwicz 2013/10/25 23:34:14 I was going to remove it as part of https://codere
oshima 2013/10/28 22:57:51 I'm happy to create CL, but may I do this in separ
pkotwicz 2013/10/29 00:46:01 I'll post a CL to remove this tomorrow (Tuesday)
59 if (!browser_frame_->non_client_view()) 99 if (!browser_frame_->non_client_view())
60 return; 100 return;
61 101
62 // If the window just moved to the top of the screen, or just moved away 102 // If the window just moved to the top of the screen, or just moved away
63 // from it, invoke Layout() so the header size can change. 103 // from it, invoke Layout() so the header size can change.
64 if ((old_bounds.y() == 0 && new_bounds.y() != 0) || 104 if ((old_bounds.y() == 0 && new_bounds.y() != 0) ||
65 (old_bounds.y() != 0 && new_bounds.y() == 0)) 105 (old_bounds.y() != 0 && new_bounds.y() == 0))
66 browser_frame_->non_client_view()->Layout(); 106 browser_frame_->non_client_view()->Layout();
67 } 107 }
68 108
(...skipping 10 matching lines...) Expand all
79 // static 119 // static
80 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh"; 120 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh";
81 121
82 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame, 122 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame,
83 BrowserView* browser_view) 123 BrowserView* browser_view)
84 : views::NativeWidgetAura(browser_frame), 124 : views::NativeWidgetAura(browser_frame),
85 browser_view_(browser_view), 125 browser_view_(browser_view),
86 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { 126 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) {
87 GetNativeWindow()->SetName(kWindowName); 127 GetNativeWindow()->SetName(kWindowName);
88 GetNativeWindow()->AddObserver(window_property_watcher_.get()); 128 GetNativeWindow()->AddObserver(window_property_watcher_.get());
89 if (browser_view->browser()->is_type_tabbed()) 129 Browser* browser = browser_view->browser();
90 ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false); 130 ash::wm::WindowState* window_state =
131 ash::wm::GetWindowState(GetNativeWindow());
132 window_state->SetDelegate(new BrowserWindowStateDelegate());
133 window_state->set_animate_to_fullscreen(!browser->is_type_tabbed());
91 134
92 // Turn on auto window management if we don't need an explicit bounds. 135 // Turn on auto window management if we don't need an explicit bounds.
93 // This way the requested bounds are honored. 136 // This way the requested bounds are honored.
94 if (!browser_view->browser()->bounds_overridden() && 137 if (!browser_view->browser()->bounds_overridden() &&
pkotwicz 2013/10/25 23:31:14 Might as well use |browser| in the remainder of th
oshima 2013/10/28 22:57:51 Done.
95 !browser_view->browser()->is_session_restore()) 138 !browser_view->browser()->is_session_restore())
96 SetWindowAutoManaged(); 139 SetWindowAutoManaged();
97 #if defined(OS_CHROMEOS) 140 #if defined(OS_CHROMEOS)
98 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys 141 // 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 142 // like brightness, volume, etc. Otherwise these keys are handled by the
100 // Ash window manager. 143 // Ash window manager.
101 if (browser_view->browser()->is_app()) { 144 window_state->set_can_consume_system_keys(browser_view->browser()->is_app());
102 ash::wm::GetWindowState(GetNativeWindow())->
103 set_can_consume_system_keys(true);
104 }
105 #endif // defined(OS_CHROMEOS) 145 #endif // defined(OS_CHROMEOS)
106 } 146 }
107 147
108 /////////////////////////////////////////////////////////////////////////////// 148 ///////////////////////////////////////////////////////////////////////////////
109 // BrowserFrameAsh, views::NativeWidgetAura overrides: 149 // BrowserFrameAsh, views::NativeWidgetAura overrides:
110 150
111 void BrowserFrameAsh::OnWindowDestroying() { 151 void BrowserFrameAsh::OnWindowDestroying() {
112 // Window is destroyed before our destructor is called, so clean up our 152 // Window is destroyed before our destructor is called, so clean up our
113 // observer here. 153 // observer here.
114 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); 154 GetNativeWindow()->RemoveObserver(window_property_watcher_.get());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 BrowserFrameAsh::~BrowserFrameAsh() { 192 BrowserFrameAsh::~BrowserFrameAsh() {
153 } 193 }
154 194
155 void BrowserFrameAsh::SetWindowAutoManaged() { 195 void BrowserFrameAsh::SetWindowAutoManaged() {
156 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || 196 if (browser_view_->browser()->type() != Browser::TYPE_POPUP ||
157 browser_view_->browser()->is_app()) { 197 browser_view_->browser()->is_app()) {
158 ash::wm::GetWindowState(GetNativeWindow())-> 198 ash::wm::GetWindowState(GetNativeWindow())->
159 set_window_position_managed(true); 199 set_window_position_managed(true);
160 } 200 }
161 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698