OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/common/ash_layout_constants.h" | 9 #include "ash/common/ash_layout_constants.h" |
10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h
" | 10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h
" |
11 #include "ash/common/frame/default_header_painter.h" | 11 #include "ash/common/frame/default_header_painter.h" |
12 #include "ash/common/frame/frame_border_hit_test.h" | 12 #include "ash/common/frame/frame_border_hit_test.h" |
13 #include "ash/common/frame/header_painter_util.h" | 13 #include "ash/common/frame/header_painter_util.h" |
14 #include "ash/common/wm_lookup.h" | 14 #include "ash/common/wm_lookup.h" |
15 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
16 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "chrome/browser/profiles/profiles_state.h" | 18 #include "chrome/browser/profiles/profiles_state.h" |
19 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
20 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 20 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/layout_constants.h" | 22 #include "chrome/browser/ui/layout_constants.h" |
23 #include "chrome/browser/ui/views/frame/browser_frame.h" | 23 #include "chrome/browser/ui/views/frame/browser_frame.h" |
24 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" | 24 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" |
25 #include "chrome/browser/ui/views/frame/browser_view.h" | 25 #include "chrome/browser/ui/views/frame/browser_view.h" |
26 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 26 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
27 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" | |
28 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" | 27 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
29 #include "chrome/browser/ui/views/tab_icon_view.h" | 28 #include "chrome/browser/ui/views/tab_icon_view.h" |
30 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 29 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
31 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 30 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
32 #include "chrome/browser/web_applications/web_app.h" | 31 #include "chrome/browser/web_applications/web_app.h" |
33 #include "chrome/grit/theme_resources.h" | 32 #include "chrome/grit/theme_resources.h" |
34 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
35 #include "ui/accessibility/ax_node_data.h" | 34 #include "ui/accessibility/ax_node_data.h" |
36 #include "ui/aura/client/aura_constants.h" | 35 #include "ui/aura/client/aura_constants.h" |
37 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
(...skipping 15 matching lines...) Expand all Loading... |
53 | 52 |
54 namespace { | 53 namespace { |
55 | 54 |
56 // Space between right edge of tabstrip and maximize button. | 55 // Space between right edge of tabstrip and maximize button. |
57 const int kTabstripRightSpacing = 10; | 56 const int kTabstripRightSpacing = 10; |
58 // Height of the shadow in the tab image, used to ensure clicks in the shadow | 57 // Height of the shadow in the tab image, used to ensure clicks in the shadow |
59 // area still drag restored windows. This keeps the clickable area large enough | 58 // area still drag restored windows. This keeps the clickable area large enough |
60 // to hit easily. | 59 // to hit easily. |
61 const int kTabShadowHeight = 4; | 60 const int kTabShadowHeight = 4; |
62 | 61 |
63 // Combines View::ConvertPointToTarget() and View::HitTest() for a given | |
64 // |point|. Converts |point| from |src| to |dst| and hit tests it against |dst|. | |
65 bool ConvertedHitTest(views::View* src, | |
66 views::View* dst, | |
67 const gfx::Point& point) { | |
68 DCHECK(src); | |
69 DCHECK(dst); | |
70 gfx::Point converted_point(point); | |
71 views::View::ConvertPointToTarget(src, dst, &converted_point); | |
72 return dst->HitTestPoint(converted_point); | |
73 } | |
74 | |
75 } // namespace | 62 } // namespace |
76 | 63 |
77 /////////////////////////////////////////////////////////////////////////////// | 64 /////////////////////////////////////////////////////////////////////////////// |
78 // BrowserNonClientFrameViewAsh, public: | 65 // BrowserNonClientFrameViewAsh, public: |
79 | 66 |
80 BrowserNonClientFrameViewAsh::BrowserNonClientFrameViewAsh( | 67 BrowserNonClientFrameViewAsh::BrowserNonClientFrameViewAsh( |
81 BrowserFrame* frame, | 68 BrowserFrame* frame, |
82 BrowserView* browser_view) | 69 BrowserView* browser_view) |
83 : BrowserNonClientFrameView(frame, browser_view), | 70 : BrowserNonClientFrameView(frame, browser_view), |
84 caption_button_container_(nullptr), | 71 caption_button_container_(nullptr), |
85 web_app_left_header_view_(nullptr), | |
86 window_icon_(nullptr) { | 72 window_icon_(nullptr) { |
87 ash::WmLookup::Get() | 73 ash::WmLookup::Get() |
88 ->GetWindowForWidget(frame) | 74 ->GetWindowForWidget(frame) |
89 ->InstallResizeHandleWindowTargeter(nullptr); | 75 ->InstallResizeHandleWindowTargeter(nullptr); |
90 ash::WmShell::Get()->AddShellObserver(this); | 76 ash::WmShell::Get()->AddShellObserver(this); |
91 } | 77 } |
92 | 78 |
93 BrowserNonClientFrameViewAsh::~BrowserNonClientFrameViewAsh() { | 79 BrowserNonClientFrameViewAsh::~BrowserNonClientFrameViewAsh() { |
94 ash::WmShell::Get()->RemoveShellObserver(this); | 80 ash::WmShell::Get()->RemoveShellObserver(this); |
95 } | 81 } |
96 | 82 |
97 void BrowserNonClientFrameViewAsh::Init() { | 83 void BrowserNonClientFrameViewAsh::Init() { |
98 caption_button_container_ = new ash::FrameCaptionButtonContainerView(frame()); | 84 caption_button_container_ = new ash::FrameCaptionButtonContainerView(frame()); |
99 caption_button_container_->UpdateSizeButtonVisibility(); | 85 caption_button_container_->UpdateSizeButtonVisibility(); |
100 AddChildView(caption_button_container_); | 86 AddChildView(caption_button_container_); |
101 | 87 |
102 // Initializing the TabIconView is expensive, so only do it if we need to. | 88 // Initializing the TabIconView is expensive, so only do it if we need to. |
103 if (browser_view()->ShouldShowWindowIcon()) { | 89 if (browser_view()->ShouldShowWindowIcon()) { |
104 window_icon_ = new TabIconView(this, nullptr); | 90 window_icon_ = new TabIconView(this, nullptr); |
105 window_icon_->set_is_light(true); | 91 window_icon_->set_is_light(true); |
106 AddChildView(window_icon_); | 92 AddChildView(window_icon_); |
107 window_icon_->Update(); | 93 window_icon_->Update(); |
108 } | 94 } |
109 | 95 |
110 if (UsePackagedAppHeaderStyle() || UseWebAppHeaderStyle()) { | 96 if (UsePackagedAppHeaderStyle()) { |
111 ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter; | 97 ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter; |
112 header_painter_.reset(header_painter); | 98 header_painter_.reset(header_painter); |
113 header_painter->Init(frame(), this, caption_button_container_); | 99 header_painter->Init(frame(), this, caption_button_container_); |
114 if (UseWebAppHeaderStyle()) { | 100 if (window_icon_) |
115 web_app_left_header_view_ = new WebAppLeftHeaderView(browser_view()); | |
116 AddChildView(web_app_left_header_view_); | |
117 header_painter->UpdateLeftHeaderView(web_app_left_header_view_); | |
118 } else if (window_icon_) { | |
119 header_painter->UpdateLeftHeaderView(window_icon_); | 101 header_painter->UpdateLeftHeaderView(window_icon_); |
120 } | |
121 } else { | 102 } else { |
122 BrowserHeaderPainterAsh* header_painter = new BrowserHeaderPainterAsh; | 103 BrowserHeaderPainterAsh* header_painter = new BrowserHeaderPainterAsh; |
123 header_painter_.reset(header_painter); | 104 header_painter_.reset(header_painter); |
124 header_painter->Init(frame(), browser_view(), this, window_icon_, | 105 header_painter->Init(frame(), browser_view(), this, window_icon_, |
125 caption_button_container_); | 106 caption_button_container_); |
126 } | 107 } |
127 | 108 |
128 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
129 if (browser_view()->browser()->is_app()) { | 110 if (browser_view()->browser()->is_app()) { |
130 frame()->GetNativeWindow()->SetProperty( | 111 frame()->GetNativeWindow()->SetProperty( |
(...skipping 22 matching lines...) Expand all Loading... |
153 return gfx::Rect(left_inset, GetTopInset(false), | 134 return gfx::Rect(left_inset, GetTopInset(false), |
154 std::max(0, width() - left_inset - GetTabStripRightInset()), | 135 std::max(0, width() - left_inset - GetTabStripRightInset()), |
155 tabstrip->GetPreferredSize().height()); | 136 tabstrip->GetPreferredSize().height()); |
156 } | 137 } |
157 | 138 |
158 int BrowserNonClientFrameViewAsh::GetTopInset(bool restored) const { | 139 int BrowserNonClientFrameViewAsh::GetTopInset(bool restored) const { |
159 if (!ShouldPaint() || UseImmersiveLightbarHeaderStyle()) | 140 if (!ShouldPaint() || UseImmersiveLightbarHeaderStyle()) |
160 return 0; | 141 return 0; |
161 | 142 |
162 if (!browser_view()->IsTabStripVisible()) { | 143 if (!browser_view()->IsTabStripVisible()) { |
163 return (UsePackagedAppHeaderStyle() || UseWebAppHeaderStyle()) | 144 return (UsePackagedAppHeaderStyle()) |
164 ? header_painter_->GetHeaderHeight() | 145 ? header_painter_->GetHeaderHeight() |
165 : caption_button_container_->bounds().bottom(); | 146 : caption_button_container_->bounds().bottom(); |
166 } | 147 } |
167 | 148 |
168 const int header_height = restored | 149 const int header_height = restored |
169 ? GetAshLayoutSize( | 150 ? GetAshLayoutSize( |
170 AshLayoutSize::BROWSER_RESTORED_CAPTION_BUTTON).height() | 151 AshLayoutSize::BROWSER_RESTORED_CAPTION_BUTTON).height() |
171 : header_painter_->GetHeaderHeight(); | 152 : header_painter_->GetHeaderHeight(); |
172 return header_height - browser_view()->GetTabStripHeight(); | 153 return header_height - browser_view()->GetTabStripHeight(); |
173 } | 154 } |
174 | 155 |
175 int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const { | 156 int BrowserNonClientFrameViewAsh::GetThemeBackgroundXInset() const { |
176 return ash::HeaderPainterUtil::GetThemeBackgroundXInset(); | 157 return ash::HeaderPainterUtil::GetThemeBackgroundXInset(); |
177 } | 158 } |
178 | 159 |
179 void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) { | 160 void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) { |
180 if (window_icon_) | 161 if (window_icon_) |
181 window_icon_->Update(); | 162 window_icon_->Update(); |
182 } | 163 } |
183 | 164 |
184 void BrowserNonClientFrameViewAsh::UpdateToolbar() { | |
185 if (web_app_left_header_view_) | |
186 web_app_left_header_view_->Update(); | |
187 } | |
188 | |
189 views::View* BrowserNonClientFrameViewAsh::GetLocationIconView() const { | |
190 return web_app_left_header_view_ ? | |
191 web_app_left_header_view_->GetLocationIconView() : nullptr; | |
192 } | |
193 | |
194 /////////////////////////////////////////////////////////////////////////////// | 165 /////////////////////////////////////////////////////////////////////////////// |
195 // views::NonClientFrameView: | 166 // views::NonClientFrameView: |
196 | 167 |
197 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForClientView() const { | 168 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForClientView() const { |
198 // The ClientView must be flush with the top edge of the widget so that the | 169 // The ClientView must be flush with the top edge of the widget so that the |
199 // web contents can take up the entire screen in immersive fullscreen (with | 170 // web contents can take up the entire screen in immersive fullscreen (with |
200 // or without the top-of-window views revealed). When in immersive fullscreen | 171 // or without the top-of-window views revealed). When in immersive fullscreen |
201 // and the top-of-window views are revealed, the TopContainerView paints the | 172 // and the top-of-window views are revealed, the TopContainerView paints the |
202 // window header by redirecting paints from its background to | 173 // window header by redirecting paints from its background to |
203 // BrowserNonClientFrameViewAsh. | 174 // BrowserNonClientFrameViewAsh. |
204 return bounds(); | 175 return bounds(); |
205 } | 176 } |
206 | 177 |
207 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( | 178 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( |
208 const gfx::Rect& client_bounds) const { | 179 const gfx::Rect& client_bounds) const { |
209 return client_bounds; | 180 return client_bounds; |
210 } | 181 } |
211 | 182 |
212 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { | 183 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { |
213 const int hit_test = | 184 const int hit_test = |
214 ash::FrameBorderNonClientHitTest(this, caption_button_container_, point); | 185 ash::FrameBorderNonClientHitTest(this, caption_button_container_, point); |
215 | 186 |
216 // See if the point is actually within the web app back button. | |
217 if (hit_test == HTCAPTION && web_app_left_header_view_ && | |
218 ConvertedHitTest(this, web_app_left_header_view_, point)) { | |
219 return HTCLIENT; | |
220 } | |
221 | |
222 // When the window is restored we want a large click target above the tabs | 187 // When the window is restored we want a large click target above the tabs |
223 // to drag the window, so redirect clicks in the tab's shadow to caption. | 188 // to drag the window, so redirect clicks in the tab's shadow to caption. |
224 if (hit_test == HTCLIENT && !frame()->IsMaximized() && | 189 if (hit_test == HTCLIENT && !frame()->IsMaximized() && |
225 !frame()->IsFullscreen()) { | 190 !frame()->IsFullscreen()) { |
226 gfx::Point client_point(point); | 191 gfx::Point client_point(point); |
227 View::ConvertPointToTarget(this, frame()->client_view(), &client_point); | 192 View::ConvertPointToTarget(this, frame()->client_view(), &client_point); |
228 gfx::Rect tabstrip_bounds(browser_view()->tabstrip()->bounds()); | 193 gfx::Rect tabstrip_bounds(browser_view()->tabstrip()->bounds()); |
229 if (client_point.y() < tabstrip_bounds.y() + kTabShadowHeight) | 194 if (client_point.y() < tabstrip_bounds.y() + kTabShadowHeight) |
230 return HTCAPTION; | 195 return HTCAPTION; |
231 } | 196 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (UseImmersiveLightbarHeaderStyle()) { | 236 if (UseImmersiveLightbarHeaderStyle()) { |
272 // The light bar header is not themed because theming it does not look good. | 237 // The light bar header is not themed because theming it does not look good. |
273 canvas->FillRect( | 238 canvas->FillRect( |
274 gfx::Rect(width(), header_painter_->GetHeaderHeightForPainting()), | 239 gfx::Rect(width(), header_painter_->GetHeaderHeightForPainting()), |
275 SK_ColorBLACK); | 240 SK_ColorBLACK); |
276 return; | 241 return; |
277 } | 242 } |
278 | 243 |
279 const bool should_paint_as_active = ShouldPaintAsActive(); | 244 const bool should_paint_as_active = ShouldPaintAsActive(); |
280 caption_button_container_->SetPaintAsActive(should_paint_as_active); | 245 caption_button_container_->SetPaintAsActive(should_paint_as_active); |
281 if (web_app_left_header_view_) | |
282 web_app_left_header_view_->SetPaintAsActive(should_paint_as_active); | |
283 | 246 |
284 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? | 247 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? |
285 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; | 248 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; |
286 header_painter_->PaintHeader(canvas, header_mode); | 249 header_painter_->PaintHeader(canvas, header_mode); |
287 | 250 |
288 if (browser_view()->IsToolbarVisible() && | 251 if (browser_view()->IsToolbarVisible() && |
289 !browser_view()->toolbar()->GetPreferredSize().IsEmpty() && | 252 !browser_view()->toolbar()->GetPreferredSize().IsEmpty() && |
290 browser_view()->IsTabStripVisible()) { | 253 browser_view()->IsTabStripVisible()) { |
291 PaintToolbarBackground(canvas); | 254 PaintToolbarBackground(canvas); |
292 } | 255 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 384 |
422 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | 385 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { |
423 const ImmersiveModeController* const immersive_controller = | 386 const ImmersiveModeController* const immersive_controller = |
424 browser_view()->immersive_mode_controller(); | 387 browser_view()->immersive_mode_controller(); |
425 return immersive_controller->IsEnabled() && | 388 return immersive_controller->IsEnabled() && |
426 !immersive_controller->IsRevealed() && | 389 !immersive_controller->IsRevealed() && |
427 browser_view()->IsTabStripVisible(); | 390 browser_view()->IsTabStripVisible(); |
428 } | 391 } |
429 | 392 |
430 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { | 393 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { |
431 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps | 394 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. |
432 // that aren't using the newer WebApp style. | |
433 const Browser* const browser = browser_view()->browser(); | 395 const Browser* const browser = browser_view()->browser(); |
434 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 396 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || |
435 (browser->is_app() && !UseWebAppHeaderStyle()); | 397 browser->is_app(); |
436 } | |
437 | |
438 bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const { | |
439 return browser_view()->browser()->SupportsWindowFeature( | |
440 Browser::FEATURE_WEBAPPFRAME); | |
441 } | 398 } |
442 | 399 |
443 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { | 400 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { |
444 DCHECK(profile_indicator_icon()); | 401 DCHECK(profile_indicator_icon()); |
445 #if !defined(OS_CHROMEOS) | 402 #if !defined(OS_CHROMEOS) |
446 // ChromeOS shows avatar on V1 app. | 403 // ChromeOS shows avatar on V1 app. |
447 DCHECK(browser_view()->IsTabStripVisible()); | 404 DCHECK(browser_view()->IsTabStripVisible()); |
448 #endif | 405 #endif |
449 | 406 |
450 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 407 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 toolbar_bounds.width(), 0); | 465 toolbar_bounds.width(), 0); |
509 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), | 466 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), |
510 separator_rect, true); | 467 separator_rect, true); |
511 | 468 |
512 // Toolbar/content separator. | 469 // Toolbar/content separator. |
513 toolbar_bounds.Inset(kClientEdgeThickness, 0); | 470 toolbar_bounds.Inset(kClientEdgeThickness, 0); |
514 BrowserView::Paint1pxHorizontalLine( | 471 BrowserView::Paint1pxHorizontalLine( |
515 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), | 472 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), |
516 toolbar_bounds, true); | 473 toolbar_bounds, true); |
517 } | 474 } |
OLD | NEW |