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

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

Issue 2552903003: Remove unreleased web app frame code from ChromeOS (Closed)
Patch Set: 'nother bit Created 4 years 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
OLDNEW
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
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
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
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 385
423 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { 386 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const {
424 const ImmersiveModeController* const immersive_controller = 387 const ImmersiveModeController* const immersive_controller =
425 browser_view()->immersive_mode_controller(); 388 browser_view()->immersive_mode_controller();
426 return immersive_controller->IsEnabled() && 389 return immersive_controller->IsEnabled() &&
427 !immersive_controller->IsRevealed() && 390 !immersive_controller->IsRevealed() &&
428 browser_view()->IsTabStripVisible(); 391 browser_view()->IsTabStripVisible();
429 } 392 }
430 393
431 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { 394 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const {
432 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps 395 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps.
433 // that aren't using the newer WebApp style.
434 const Browser* const browser = browser_view()->browser(); 396 const Browser* const browser = browser_view()->browser();
435 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || 397 return (!browser->is_type_tabbed() && browser->is_trusted_source()) ||
436 (browser->is_app() && !UseWebAppHeaderStyle()); 398 browser->is_app();
437 }
438
439 bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const {
440 return browser_view()->browser()->SupportsWindowFeature(
441 Browser::FEATURE_WEBAPPFRAME);
442 } 399 }
443 400
444 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { 401 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() {
445 DCHECK(profile_indicator_icon()); 402 DCHECK(profile_indicator_icon());
446 #if !defined(OS_CHROMEOS) 403 #if !defined(OS_CHROMEOS)
447 // ChromeOS shows avatar on V1 app. 404 // ChromeOS shows avatar on V1 app.
448 DCHECK(browser_view()->IsTabStripVisible()); 405 DCHECK(browser_view()->IsTabStripVisible());
449 #endif 406 #endif
450 407
451 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); 408 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 toolbar_bounds.width(), 0); 466 toolbar_bounds.width(), 0);
510 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), 467 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(),
511 separator_rect, true); 468 separator_rect, true);
512 469
513 // Toolbar/content separator. 470 // Toolbar/content separator.
514 toolbar_bounds.Inset(kClientEdgeThickness, 0); 471 toolbar_bounds.Inset(kClientEdgeThickness, 0);
515 BrowserView::Paint1pxHorizontalLine( 472 BrowserView::Paint1pxHorizontalLine(
516 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), 473 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
517 toolbar_bounds, true); 474 toolbar_bounds, true);
518 } 475 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698