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_ash.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "ash/wm/window_state.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "ash/wm/window_util.h" |
9 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
10 #include "grit/chromium_strings.h" | |
11 #include "grit/generated_resources.h" | |
12 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
13 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
14 #include "ui/aura/window_observer.h" | 12 #include "ui/aura/window_observer.h" |
15 #include "ui/base/hit_test.h" | |
16 #include "ui/base/l10n/l10n_util.h" | |
17 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" |
James Cook
2013/10/03 22:14:57
You might not need this any more
| |
18 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
19 | 15 |
20 #if defined(USE_ASH) | |
21 #include "ash/wm/window_state.h" | |
22 #include "ash/wm/window_util.h" | |
23 #endif | |
24 | |
25 using aura::Window; | 16 using aura::Window; |
26 | 17 |
27 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
28 // BrowserFrameAura::WindowPropertyWatcher | 19 // BrowserFrameAsh::WindowPropertyWatcher |
29 | 20 |
30 class BrowserFrameAura::WindowPropertyWatcher : public aura::WindowObserver { | 21 class BrowserFrameAsh::WindowPropertyWatcher : public aura::WindowObserver { |
31 public: | 22 public: |
32 explicit WindowPropertyWatcher(BrowserFrameAura* browser_frame_aura, | 23 explicit WindowPropertyWatcher(BrowserFrameAsh* browser_frame_ash, |
33 BrowserFrame* browser_frame) | 24 BrowserFrame* browser_frame) |
34 : browser_frame_aura_(browser_frame_aura), | 25 : browser_frame_ash_(browser_frame_ash), |
35 browser_frame_(browser_frame) {} | 26 browser_frame_(browser_frame) {} |
36 | 27 |
37 virtual void OnWindowPropertyChanged(aura::Window* window, | 28 virtual void OnWindowPropertyChanged(aura::Window* window, |
38 const void* key, | 29 const void* key, |
39 intptr_t old) OVERRIDE { | 30 intptr_t old) OVERRIDE { |
40 if (key != aura::client::kShowStateKey) | 31 if (key != aura::client::kShowStateKey) |
41 return; | 32 return; |
42 | 33 |
43 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | 34 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); |
44 ui::WindowShowState new_state = | 35 ui::WindowShowState new_state = |
45 window->GetProperty(aura::client::kShowStateKey); | 36 window->GetProperty(aura::client::kShowStateKey); |
46 | 37 |
47 // Allow the frame to be replaced when entering or exiting the maximized | 38 // Allow the frame to be replaced when entering or exiting the maximized |
48 // state. | 39 // state. |
49 if (browser_frame_->non_client_view() && | 40 if (browser_frame_->non_client_view() && |
50 browser_frame_aura_->browser_view()->browser()->is_app() && | 41 browser_frame_ash_->browser_view()->browser()->is_app() && |
51 (old_state == ui::SHOW_STATE_MAXIMIZED || | 42 (old_state == ui::SHOW_STATE_MAXIMIZED || |
52 new_state == ui::SHOW_STATE_MAXIMIZED)) { | 43 new_state == ui::SHOW_STATE_MAXIMIZED)) { |
53 // Defer frame layout when replacing the frame. Layout will occur when the | 44 // Defer frame layout when replacing the frame. Layout will occur when the |
54 // window's bounds are updated. The window maximize/restore animations | 45 // window's bounds are updated. The window maximize/restore animations |
55 // clone the window's layers and rely on the subsequent layout to set | 46 // clone the window's layers and rely on the subsequent layout to set |
56 // the layer sizes. | 47 // the layer sizes. |
57 // If the window is minimized, the frame view needs to be updated via | 48 // If the window is minimized, the frame view needs to be updated via |
58 // an OnBoundsChanged event so that the frame will change its size | 49 // an OnBoundsChanged event so that the frame will change its size |
59 // properly. | 50 // properly. |
60 browser_frame_->non_client_view()->UpdateFrame( | 51 browser_frame_->non_client_view()->UpdateFrame( |
61 old_state == ui::SHOW_STATE_MINIMIZED); | 52 old_state == ui::SHOW_STATE_MINIMIZED); |
62 } | 53 } |
63 } | 54 } |
64 | 55 |
65 virtual void OnWindowBoundsChanged(aura::Window* window, | 56 virtual void OnWindowBoundsChanged(aura::Window* window, |
66 const gfx::Rect& old_bounds, | 57 const gfx::Rect& old_bounds, |
67 const gfx::Rect& new_bounds) OVERRIDE { | 58 const gfx::Rect& new_bounds) OVERRIDE { |
68 // Don't do anything if we don't have our non-client view yet. | 59 // Don't do anything if we don't have our non-client view yet. |
69 if (!browser_frame_->non_client_view()) | 60 if (!browser_frame_->non_client_view()) |
70 return; | 61 return; |
71 | 62 |
72 // If the window just moved to the top of the screen, or just moved away | 63 // If the window just moved to the top of the screen, or just moved away |
73 // from it, invoke Layout() so the header size can change. | 64 // from it, invoke Layout() so the header size can change. |
74 if ((old_bounds.y() == 0 && new_bounds.y() != 0) || | 65 if ((old_bounds.y() == 0 && new_bounds.y() != 0) || |
75 (old_bounds.y() != 0 && new_bounds.y() == 0)) | 66 (old_bounds.y() != 0 && new_bounds.y() == 0)) |
76 browser_frame_->non_client_view()->Layout(); | 67 browser_frame_->non_client_view()->Layout(); |
77 } | 68 } |
78 | 69 |
79 private: | 70 private: |
80 BrowserFrameAura* browser_frame_aura_; | 71 BrowserFrameAsh* browser_frame_ash_; |
81 BrowserFrame* browser_frame_; | 72 BrowserFrame* browser_frame_; |
82 | 73 |
83 DISALLOW_COPY_AND_ASSIGN(WindowPropertyWatcher); | 74 DISALLOW_COPY_AND_ASSIGN(WindowPropertyWatcher); |
84 }; | 75 }; |
85 | 76 |
86 /////////////////////////////////////////////////////////////////////////////// | 77 /////////////////////////////////////////////////////////////////////////////// |
87 // BrowserFrameAura, public: | 78 // BrowserFrameAsh, public: |
88 | 79 |
89 // static | 80 // static |
90 const char BrowserFrameAura::kWindowName[] = "BrowserFrameAura"; | 81 const char BrowserFrameAsh::kWindowName[] = "BrowserFrameAsh"; |
91 | 82 |
92 BrowserFrameAura::BrowserFrameAura(BrowserFrame* browser_frame, | 83 BrowserFrameAsh::BrowserFrameAsh(BrowserFrame* browser_frame, |
93 BrowserView* browser_view) | 84 BrowserView* browser_view) |
94 : views::NativeWidgetAura(browser_frame), | 85 : views::NativeWidgetAura(browser_frame), |
95 browser_view_(browser_view), | 86 browser_view_(browser_view), |
96 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { | 87 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { |
97 GetNativeWindow()->SetName(kWindowName); | 88 GetNativeWindow()->SetName(kWindowName); |
98 GetNativeWindow()->AddObserver(window_property_watcher_.get()); | 89 GetNativeWindow()->AddObserver(window_property_watcher_.get()); |
99 #if defined(USE_ASH) | |
100 if (browser_view->browser()->is_type_tabbed()) | 90 if (browser_view->browser()->is_type_tabbed()) |
101 ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false); | 91 ash::wm::SetAnimateToFullscreen(GetNativeWindow(), false); |
102 | 92 |
103 // Turn on auto window management if we don't need an explicit bounds. | 93 // Turn on auto window management if we don't need an explicit bounds. |
104 // This way the requested bounds are honored. | 94 // This way the requested bounds are honored. |
105 if (!browser_view->browser()->bounds_overridden() && | 95 if (!browser_view->browser()->bounds_overridden() && |
106 !browser_view->browser()->is_session_restore()) | 96 !browser_view->browser()->is_session_restore()) |
107 SetWindowAutoManaged(); | 97 SetWindowAutoManaged(); |
108 #endif | |
109 #if defined(OS_CHROMEOS) | 98 #if defined(OS_CHROMEOS) |
110 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys | 99 // For legacy reasons v1 apps (like Secure Shell) are allowed to consume keys |
111 // like brightness, volume, etc. Otherwise these keys are handled by the | 100 // like brightness, volume, etc. Otherwise these keys are handled by the |
112 // Ash window manager. | 101 // Ash window manager. |
113 if (browser_view->browser()->is_app()) { | 102 if (browser_view->browser()->is_app()) { |
114 ash::wm::GetWindowState(GetNativeWindow())-> | 103 ash::wm::GetWindowState(GetNativeWindow())-> |
115 set_can_consume_system_keys(true); | 104 set_can_consume_system_keys(true); |
116 } | 105 } |
117 #endif // defined(OS_CHROMEOS) | 106 #endif // defined(OS_CHROMEOS) |
118 } | 107 } |
119 | 108 |
120 /////////////////////////////////////////////////////////////////////////////// | 109 /////////////////////////////////////////////////////////////////////////////// |
121 // BrowserFrameAura, views::NativeWidgetAura overrides: | 110 // BrowserFrameAsh, views::NativeWidgetAura overrides: |
122 | 111 |
123 void BrowserFrameAura::OnWindowDestroying() { | 112 void BrowserFrameAsh::OnWindowDestroying() { |
124 // Window is destroyed before our destructor is called, so clean up our | 113 // Window is destroyed before our destructor is called, so clean up our |
125 // observer here. | 114 // observer here. |
126 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); | 115 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); |
127 views::NativeWidgetAura::OnWindowDestroying(); | 116 views::NativeWidgetAura::OnWindowDestroying(); |
128 } | 117 } |
129 | 118 |
130 void BrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) { | 119 void BrowserFrameAsh::OnWindowTargetVisibilityChanged(bool visible) { |
131 if (visible) { | 120 if (visible) { |
132 // Once the window has been shown we know the requested bounds | 121 // Once the window has been shown we know the requested bounds |
133 // (if provided) have been honored and we can switch on window management. | 122 // (if provided) have been honored and we can switch on window management. |
134 SetWindowAutoManaged(); | 123 SetWindowAutoManaged(); |
135 } | 124 } |
136 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); | 125 views::NativeWidgetAura::OnWindowTargetVisibilityChanged(visible); |
137 } | 126 } |
138 | 127 |
139 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
140 // BrowserFrameAura, NativeBrowserFrame implementation: | 129 // BrowserFrameAsh, NativeBrowserFrame implementation: |
141 | 130 |
142 views::NativeWidget* BrowserFrameAura::AsNativeWidget() { | 131 views::NativeWidget* BrowserFrameAsh::AsNativeWidget() { |
143 return this; | 132 return this; |
144 } | 133 } |
145 | 134 |
146 const views::NativeWidget* BrowserFrameAura::AsNativeWidget() const { | 135 const views::NativeWidget* BrowserFrameAsh::AsNativeWidget() const { |
147 return this; | 136 return this; |
148 } | 137 } |
149 | 138 |
150 bool BrowserFrameAura::UsesNativeSystemMenu() const { | 139 bool BrowserFrameAsh::UsesNativeSystemMenu() const { |
151 return false; | 140 return false; |
152 } | 141 } |
153 | 142 |
154 int BrowserFrameAura::GetMinimizeButtonOffset() const { | 143 int BrowserFrameAsh::GetMinimizeButtonOffset() const { |
155 return 0; | 144 return 0; |
156 } | 145 } |
157 | 146 |
158 void BrowserFrameAura::TabStripDisplayModeChanged() { | 147 void BrowserFrameAsh::TabStripDisplayModeChanged() { |
159 } | |
160 | |
161 //////////////////////////////////////////////////////////////////////////////// | |
162 // BrowserFrame, public: | |
163 | |
164 // static | |
165 const gfx::Font& BrowserFrame::GetTitleFont() { | |
166 static gfx::Font* title_font = new gfx::Font; | |
167 return *title_font; | |
168 } | 148 } |
169 | 149 |
170 /////////////////////////////////////////////////////////////////////////////// | 150 /////////////////////////////////////////////////////////////////////////////// |
171 // BrowserFrameAura, private: | 151 // BrowserFrameAsh, private: |
172 | 152 |
173 BrowserFrameAura::~BrowserFrameAura() { | 153 BrowserFrameAsh::~BrowserFrameAsh() { |
174 } | 154 } |
175 | 155 |
176 void BrowserFrameAura::SetWindowAutoManaged() { | 156 void BrowserFrameAsh::SetWindowAutoManaged() { |
177 #if defined(USE_ASH) | |
178 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || | 157 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || |
179 browser_view_->browser()->is_app()) { | 158 browser_view_->browser()->is_app()) { |
180 ash::wm::GetWindowState(GetNativeWindow())-> | 159 ash::wm::GetWindowState(GetNativeWindow())-> |
181 set_window_position_managed(true); | 160 set_window_position_managed(true); |
182 } | 161 } |
183 #endif | |
184 } | 162 } |
OLD | NEW |