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

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

Issue 1643453002: Completely rewrite OpaqueBrowserFrameViewLayout unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewrite Created 4 years, 10 months 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 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/opaque_browser_frame_view_layout.h" 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/profiles/profiles_state.h" 9 #include "chrome/browser/profiles/profiles_state.h"
10 #include "chrome/browser/ui/layout_constants.h" 10 #include "chrome/browser/ui/layout_constants.h"
11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "components/signin/core/common/profile_management_switches.h" 13 #include "components/signin/core/common/profile_management_switches.h"
14 #include "ui/base/material_design/material_design_controller.h" 14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
16 #include "ui/views/controls/button/image_button.h" 16 #include "ui/views/controls/button/image_button.h"
17 #include "ui/views/controls/label.h" 17 #include "ui/views/controls/label.h"
18 18
19 namespace { 19 namespace {
20 20
21 // Besides the frame border, there's empty space atop the window in restored
22 // mode, to use to drag the window around.
23 const int kNonClientRestoredExtraThickness = 11;
24
25 // The titlebar never shrinks too short to show the caption button plus some 21 // The titlebar never shrinks too short to show the caption button plus some
26 // padding below it. 22 // padding below it.
27 const int kCaptionButtonHeight = 18; 23 const int kCaptionButtonHeight = 18;
28 const int kTitleBarAdditionalPadding = 3; 24 const int kTitleBarAdditionalPadding = 3;
29 25
30 // There is a 5 px gap between the title text and the caption buttons.
31 const int kTitleLogoSpacing = 5;
32
33 // The frame border is only visible in restored mode and is hardcoded to 4 px on
34 // each side regardless of the system window border size.
35 const int kFrameBorderThickness = 4;
36
37 // The titlebar has a 2 px 3D edge along the top and bottom.
38 const int kTitlebarTopAndBottomEdgeThickness = 2;
39
40 // The icon is inset 2 px from the left frame border.
41 const int kIconLeftSpacing = 2;
42
43 // There is a 4 px gap between the icon and the title text.
44 const int kIconTitleSpacing = 4;
45
46 // How far the new avatar button is from the closest caption button.
47 const int kNewAvatarButtonOffset = 5;
48
49 // When the title bar is in its normal two row mode (usually the case for
50 // restored windows), the New Tab button isn't at the same height as the caption
51 // buttons, but the space will look cluttered if it actually slides under them,
52 // so we stop it when the gap between the two is down to 5 px.
53 const int kNewTabCaptionNormalSpacing = 5;
54
55 // When the title bar is condensed to one row (as when maximized), the New Tab
56 // button and the caption buttons are at similar vertical coordinates, so we
57 // need to reserve a larger, 16 px gap to avoid looking too cluttered.
58 const int kNewTabCaptionCondensedSpacing = 16;
59
60 // If there are no caption buttons to the right of the New Tab button, we
61 // reserve a small 5px gap, regardless of whether the window is maximized. This
62 // overrides the two previous constants.
63 const int kNewTabNoCaptionButtonsSpacing = 5;
64
65 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 26 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
66 // Default extra space between the top of the frame and the top of the window 27 // Default extra space between the top of the frame and the top of the window
67 // caption buttons. 28 // caption buttons.
68 const int kExtraCaption = 2; 29 const int kExtraCaption = 2;
69 30
70 // Default extra spacing between individual window caption buttons. 31 // Default extra spacing between individual window caption buttons.
71 const int kCaptionButtonSpacing = 2; 32 const int kCaptionButtonSpacing = 2;
72 #else 33 #else
73 const int kExtraCaption = 0; 34 const int kExtraCaption = 0;
74 const int kCaptionButtonSpacing = 0; 35 const int kCaptionButtonSpacing = 0;
75 #endif 36 #endif
76 37
77 } // namespace 38 } // namespace
78 39
79 /////////////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////////////
80 // OpaqueBrowserFrameView, public: 41 // OpaqueBrowserFrameView, public:
81 42
43 // statics
44
45 // Besides the frame border, there's empty space atop the window in restored
46 // mode, to use to drag the window around.
47 const int OpaqueBrowserFrameViewLayout::kNonClientRestoredExtraThickness = 11;
48
49 // The frame border is only visible in restored mode and is hardcoded to 4 px on
50 // each side regardless of the system window border size.
51 const int OpaqueBrowserFrameViewLayout::kFrameBorderThickness = 4;
52
53 // The titlebar has a 2 px 3D edge along the top and bottom.
54 const int OpaqueBrowserFrameViewLayout::kTitlebarTopAndBottomEdgeThickness = 2;
55
56 // The icon is inset 2 px from the left frame border.
57 const int OpaqueBrowserFrameViewLayout::kIconLeftSpacing = 2;
58
59 // There is a 4 px gap between the icon and the title text.
60 const int OpaqueBrowserFrameViewLayout::kIconTitleSpacing = 4;
61
62 // The horizontal spacing to use in most cases when laying out things near the
63 // caption button area.
64 const int OpaqueBrowserFrameViewLayout::kCaptionSpacing = 5;
65
66 // When the title bar is condensed to one row (as when maximized), the New Tab
67 // button and the caption buttons are at similar vertical coordinates, so we
68 // need to reserve a larger, 16 px gap to avoid looking too cluttered.
69 const int OpaqueBrowserFrameViewLayout::kNewTabCaptionCondensedSpacing = 16;
70
71
82 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout( 72 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout(
83 OpaqueBrowserFrameViewLayoutDelegate* delegate) 73 OpaqueBrowserFrameViewLayoutDelegate* delegate)
84 : delegate_(delegate), 74 : delegate_(delegate),
85 leading_button_start_(0), 75 leading_button_start_(0),
86 trailing_button_start_(0), 76 trailing_button_start_(0),
87 minimum_size_for_buttons_(0), 77 minimum_size_for_buttons_(0),
88 has_leading_buttons_(false), 78 has_leading_buttons_(false),
89 has_trailing_buttons_(false), 79 has_trailing_buttons_(false),
90 extra_caption_y_(kExtraCaption), 80 extra_caption_y_(kExtraCaption),
91 window_caption_spacing_(kCaptionButtonSpacing), 81 window_caption_spacing_(kCaptionButtonSpacing),
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 /////////////////////////////////////////////////////////////////////////////// 227 ///////////////////////////////////////////////////////////////////////////////
238 // OpaqueBrowserFrameView, private: 228 // OpaqueBrowserFrameView, private:
239 229
240 bool OpaqueBrowserFrameViewLayout::ShouldIncognitoIconBeOnRight() const { 230 bool OpaqueBrowserFrameViewLayout::ShouldIncognitoIconBeOnRight() const {
241 // The incognito should be shown either on the end of the left or the 231 // The incognito should be shown either on the end of the left or the
242 // beginning of the right, depending on which side has fewer buttons. 232 // beginning of the right, depending on which side has fewer buttons.
243 return trailing_buttons_.size() < leading_buttons_.size(); 233 return trailing_buttons_.size() < leading_buttons_.size();
244 } 234 }
245 235
246 int OpaqueBrowserFrameViewLayout::NewTabCaptionSpacing() const { 236 int OpaqueBrowserFrameViewLayout::NewTabCaptionSpacing() const {
247 if (!has_trailing_buttons_) 237 return (has_trailing_buttons_ && IsTitleBarCondensed()) ?
248 return kNewTabNoCaptionButtonsSpacing; 238 kNewTabCaptionCondensedSpacing : kCaptionSpacing;
249 return IsTitleBarCondensed() ?
250 kNewTabCaptionCondensedSpacing : kNewTabCaptionNormalSpacing;
251 } 239 }
252 240
253 void OpaqueBrowserFrameViewLayout::LayoutWindowControls(views::View* host) { 241 void OpaqueBrowserFrameViewLayout::LayoutWindowControls(views::View* host) {
254 int caption_y = CaptionButtonY(false); 242 int caption_y = CaptionButtonY(false);
255 243
256 // Keep a list of all buttons that we don't show. 244 // Keep a list of all buttons that we don't show.
257 std::vector<views::FrameButton> buttons_not_shown; 245 std::vector<views::FrameButton> buttons_not_shown;
258 buttons_not_shown.push_back(views::FRAME_BUTTON_MAXIMIZE); 246 buttons_not_shown.push_back(views::FRAME_BUTTON_MAXIMIZE);
259 buttons_not_shown.push_back(views::FRAME_BUTTON_MINIMIZE); 247 buttons_not_shown.push_back(views::FRAME_BUTTON_MINIMIZE);
260 buttons_not_shown.push_back(views::FRAME_BUTTON_CLOSE); 248 buttons_not_shown.push_back(views::FRAME_BUTTON_CLOSE);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 310
323 if (should_show_icon) 311 if (should_show_icon)
324 window_icon_->SetBoundsRect(window_icon_bounds_); 312 window_icon_->SetBoundsRect(window_icon_bounds_);
325 313
326 if (window_title_) { 314 if (window_title_) {
327 window_title_->SetVisible(should_show_title); 315 window_title_->SetVisible(should_show_title);
328 if (should_show_title) { 316 if (should_show_title) {
329 window_title_->SetText(delegate_->GetWindowTitle()); 317 window_title_->SetText(delegate_->GetWindowTitle());
330 318
331 int text_width = std::max( 319 int text_width = std::max(
332 0, host->width() - trailing_button_start_ - kTitleLogoSpacing - 320 0, host->width() - trailing_button_start_ - kCaptionSpacing -
333 leading_button_start_ - kIconTitleSpacing); 321 leading_button_start_ - kIconTitleSpacing);
334 window_title_->SetBounds(leading_button_start_ + kIconTitleSpacing, 322 window_title_->SetBounds(leading_button_start_ + kIconTitleSpacing,
335 window_icon_bounds_.y(), 323 window_icon_bounds_.y(),
336 text_width, window_icon_bounds_.height()); 324 text_width, window_icon_bounds_.height());
337 leading_button_start_ += text_width + kIconTitleSpacing; 325 leading_button_start_ += text_width + kIconTitleSpacing;
338 } 326 }
339 } 327 }
340 328
341 if (use_hidden_icon_location) { 329 if (use_hidden_icon_location) {
342 if (has_leading_buttons_) { 330 if (has_leading_buttons_) {
343 // There are window button icons on the left. Don't size the hidden window 331 // There are window button icons on the left. Don't size the hidden window
344 // icon that people can double click on to close the window. 332 // icon that people can double click on to close the window.
345 window_icon_bounds_ = gfx::Rect(); 333 window_icon_bounds_ = gfx::Rect();
346 } else { 334 } else {
347 // We set the icon bounds to a small rectangle in the top leading corner 335 // We set the icon bounds to a small rectangle in the top leading corner
348 // if there are no icons on the leading side. 336 // if there are no icons on the leading side.
349 window_icon_bounds_ = gfx::Rect( 337 window_icon_bounds_ = gfx::Rect(
350 frame_thickness + kIconLeftSpacing, frame_thickness, size, size); 338 frame_thickness + kIconLeftSpacing, frame_thickness, size, size);
351 } 339 }
352 } 340 }
353 } 341 }
354 342
355 void OpaqueBrowserFrameViewLayout::LayoutNewStyleAvatar(views::View* host) { 343 void OpaqueBrowserFrameViewLayout::LayoutNewStyleAvatar(views::View* host) {
356 if (!new_avatar_button_) 344 if (!new_avatar_button_)
357 return; 345 return;
358 346
359 int button_width = new_avatar_button_->GetPreferredSize().width(); 347 int button_width = new_avatar_button_->GetPreferredSize().width();
360 int button_width_with_offset = button_width + kNewAvatarButtonOffset; 348 int button_width_with_offset = button_width + kCaptionSpacing;
361 349
362 int button_x = 350 int button_x =
363 host->width() - trailing_button_start_ - button_width_with_offset; 351 host->width() - trailing_button_start_ - button_width_with_offset;
364 int button_y = CaptionButtonY(!IsTitleBarCondensed()); 352 int button_y = CaptionButtonY(!IsTitleBarCondensed());
365 353
366 minimum_size_for_buttons_ += button_width_with_offset; 354 minimum_size_for_buttons_ += button_width_with_offset;
367 trailing_button_start_ += button_width_with_offset; 355 trailing_button_start_ += button_width_with_offset;
368 356
369 // In non-maximized mode, allow the new tab button to completely slide under 357 // In non-maximized mode, allow the new tab button to completely slide under
370 // the avatar button. 358 // the avatar button.
371 if (!IsTitleBarCondensed()) { 359 if (!IsTitleBarCondensed()) {
372 trailing_button_start_ -= 360 trailing_button_start_ -=
373 GetLayoutSize(NEW_TAB_BUTTON).width() + kNewTabCaptionNormalSpacing; 361 GetLayoutSize(NEW_TAB_BUTTON).width() + kCaptionSpacing;
374 } 362 }
375 363
376 new_avatar_button_->SetBounds(button_x, button_y, button_width, 364 new_avatar_button_->SetBounds(button_x, button_y, button_width,
377 kCaptionButtonHeight); 365 kCaptionButtonHeight);
378 } 366 }
379 367
380 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) { 368 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) {
381 const int old_button_size = leading_button_start_ + trailing_button_start_; 369 const int old_button_size = leading_button_start_ + trailing_button_start_;
382 370
383 // Any buttons/icon/title were laid out based on the frame border thickness, 371 // Any buttons/icon/title were laid out based on the frame border thickness,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 int extra_height = title_bar_condensed ? extra_caption_y_ : 0; 480 int extra_height = title_bar_condensed ? extra_caption_y_ : 0;
493 481
494 switch (alignment) { 482 switch (alignment) {
495 case ALIGN_LEADING: { 483 case ALIGN_LEADING: {
496 if (has_leading_buttons_) 484 if (has_leading_buttons_)
497 leading_button_start_ += window_caption_spacing_; 485 leading_button_start_ += window_caption_spacing_;
498 486
499 // If we're the first button on the left and maximized, add width to the 487 // If we're the first button on the left and maximized, add width to the
500 // right hand side of the screen. 488 // right hand side of the screen.
501 int extra_width = (title_bar_condensed && !has_leading_buttons_) ? 489 int extra_width = (title_bar_condensed && !has_leading_buttons_) ?
502 (kFrameBorderThickness - 490 (kFrameBorderThickness -
503 views::NonClientFrameView::kFrameShadowThickness) : 0; 491 views::NonClientFrameView::kFrameShadowThickness) :
492 0;
504 493
505 button->SetBounds( 494 button->SetBounds(leading_button_start_,
506 leading_button_start_, 495 caption_y - extra_height,
507 caption_y - extra_height, 496 button_size.width() + extra_width,
508 button_size.width() + extra_width, 497 button_size.height() + extra_height);
509 button_size.height() + extra_height);
510 498
511 leading_button_start_ += extra_width + button_size.width(); 499 leading_button_start_ += extra_width + button_size.width();
512 minimum_size_for_buttons_ += extra_width + button_size.width(); 500 minimum_size_for_buttons_ += extra_width + button_size.width();
513 has_leading_buttons_ = true; 501 has_leading_buttons_ = true;
514 break; 502 break;
515 } 503 }
516 case ALIGN_TRAILING: { 504 case ALIGN_TRAILING: {
517 if (has_trailing_buttons_) 505 if (has_trailing_buttons_)
518 trailing_button_start_ += window_caption_spacing_; 506 trailing_button_start_ += window_caption_spacing_;
519 507
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 619
632 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, 620 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host,
633 views::View* view) { 621 views::View* view) {
634 SetView(view->id(), view); 622 SetView(view->id(), view);
635 } 623 }
636 624
637 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, 625 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host,
638 views::View* view) { 626 views::View* view) {
639 SetView(view->id(), nullptr); 627 SetView(view->id(), nullptr);
640 } 628 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698