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

Side by Side Diff: chrome/browser/ui/infobar_container_delegate.cc

Issue 1826653002: Draw infobar arrow border with width of 1px on any scale factor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move path calc Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/infobar_container_delegate.h" 5 #include "chrome/browser/ui/infobar_container_delegate.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "ui/base/material_design/material_design_controller.h" 8 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/gfx/animation/slide_animation.h" 9 #include "ui/gfx/animation/slide_animation.h"
10 10
11 #if defined(TOOLKIT_VIEWS) 11 #if defined(TOOLKIT_VIEWS)
12 #include "ui/views/window/non_client_view.h" 12 #include "ui/views/window/non_client_view.h"
13 #endif 13 #endif
14 14
15 namespace {
16
17 int GetDefaultArrowTargetHeight() {
18 return ui::MaterialDesignController::IsModeMaterial()
19 ? InfoBarContainerDelegate::kDefaultArrowTargetHeightMd
20 : InfoBarContainerDelegate::kDefaultArrowTargetHeight;
21 }
22
23 int GetDefaultArrowTargetHalfWidth() {
24 return ui::MaterialDesignController::IsModeMaterial()
25 ? InfoBarContainerDelegate::kDefaultArrowTargetHalfWidthMd
26 : InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth;
27 }
28
29 } // namespace
30
15 // static 31 // static
16 #if defined(OS_MACOSX) 32 #if defined(OS_MACOSX)
17 const int InfoBarContainerDelegate::kSeparatorLineHeight = 1; 33 const int InfoBarContainerDelegate::kSeparatorLineHeight = 1;
18 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 11; 34 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 11;
19 #elif defined(TOOLKIT_VIEWS) 35 #elif defined(TOOLKIT_VIEWS)
20 // Views comes second until the Mac browser is Views-based. 36 // Views comes second until the Mac browser is Views-based.
21 const int InfoBarContainerDelegate::kSeparatorLineHeight = 37 const int InfoBarContainerDelegate::kSeparatorLineHeight =
22 views::NonClientFrameView::kClientEdgeThickness; 38 views::NonClientFrameView::kClientEdgeThickness;
23 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 9; 39 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 9;
40 const int InfoBarContainerDelegate::kDefaultArrowTargetHeightMd = 11;
24 #endif 41 #endif
25 42
26 const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 36; 43 const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 36;
27 const int InfoBarContainerDelegate::kDefaultBarTargetHeightMd = 40; 44 const int InfoBarContainerDelegate::kDefaultBarTargetHeightMd = 40;
28 const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24; 45 const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24;
29 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth = 46 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth =
30 kDefaultArrowTargetHeight; 47 kDefaultArrowTargetHeight;
48 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidthMd =
49 kDefaultArrowTargetHeightMd;
31 const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14; 50 const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14;
32 51
33 InfoBarContainerDelegate::InfoBarContainerDelegate() 52 InfoBarContainerDelegate::InfoBarContainerDelegate()
34 : top_arrow_target_height_(kDefaultArrowTargetHeight) { 53 : top_arrow_target_height_(kDefaultArrowTargetHeight) {
35 } 54 }
36 55
37 InfoBarContainerDelegate::~InfoBarContainerDelegate() { 56 InfoBarContainerDelegate::~InfoBarContainerDelegate() {
38 } 57 }
39 58
40 void InfoBarContainerDelegate::SetMaxTopArrowHeight( 59 void InfoBarContainerDelegate::SetMaxTopArrowHeight(
41 int height, 60 int height,
42 infobars::InfoBarContainer* container) { 61 infobars::InfoBarContainer* container) {
43 // Decrease the height by the arrow stroke thickness, which is the separator 62 // Decrease the height by the arrow stroke thickness, which is the separator
44 // line height, because the infobar arrow target heights are without-stroke. 63 // line height, because the infobar arrow target heights are without-stroke.
45 top_arrow_target_height_ = std::min( 64 top_arrow_target_height_ = std::min(
46 std::max(height - kSeparatorLineHeight, 0), kMaximumArrowTargetHeight); 65 std::max(height - kSeparatorLineHeight, 0), kMaximumArrowTargetHeight);
47 container->UpdateInfoBarArrowTargetHeights(); 66 container->UpdateInfoBarArrowTargetHeights();
48 } 67 }
49 68
50 int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar( 69 int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar(
51 size_t index, 70 size_t index,
52 const gfx::SlideAnimation& animation) const { 71 const gfx::SlideAnimation& animation) const {
53 if (!DrawInfoBarArrows(nullptr)) 72 if (!DrawInfoBarArrows(nullptr))
54 return 0; 73 return 0;
55 if (index == 0) 74 if (index == 0)
56 return top_arrow_target_height_; 75 return top_arrow_target_height_;
57 if ((index > 1) || animation.IsShowing()) 76 if ((index > 1) || animation.IsShowing())
58 return kDefaultArrowTargetHeight; 77 return GetDefaultArrowTargetHeight();
59 // When the first infobar is animating closed, we animate the second infobar's 78 // When the first infobar is animating closed, we animate the second infobar's
60 // arrow target height from the default to the top target height. Note that 79 // arrow target height from the default to the top target height. Note that
61 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. 80 // the animation values here are going from 1.0 -> 0.0 as the top bar closes.
62 return top_arrow_target_height_ + static_cast<int>( 81 return top_arrow_target_height_ +
63 (kDefaultArrowTargetHeight - top_arrow_target_height_) * 82 static_cast<int>(
64 animation.GetCurrentValue()); 83 (GetDefaultArrowTargetHeight() - top_arrow_target_height_) *
84 animation.GetCurrentValue());
65 } 85 }
66 86
67 void InfoBarContainerDelegate::ComputeInfoBarElementSizes( 87 void InfoBarContainerDelegate::ComputeInfoBarElementSizes(
68 const gfx::SlideAnimation& animation, 88 const gfx::SlideAnimation& animation,
69 int arrow_target_height, 89 int arrow_target_height,
70 int bar_target_height, 90 int bar_target_height,
71 int* arrow_height, 91 int* arrow_height,
72 int* arrow_half_width, 92 int* arrow_half_width,
73 int* bar_height) const { 93 int* bar_height) const {
74 // Find the desired arrow height/half-width. The arrow area is 94 // Find the desired arrow height/half-width. The arrow area is
75 // *arrow_height * *arrow_half_width. When the bar is opening or closing, 95 // *arrow_height * *arrow_half_width. When the bar is opening or closing,
76 // scaling each of these with the square root of the animation value causes a 96 // scaling each of these with the square root of the animation value causes a
77 // linear animation of the area, which matches the perception of the animation 97 // linear animation of the area, which matches the perception of the animation
78 // of the bar portion. 98 // of the bar portion.
79 double scale_factor = sqrt(animation.GetCurrentValue()); 99 double scale_factor = sqrt(animation.GetCurrentValue());
80 *arrow_height = static_cast<int>(arrow_target_height * scale_factor); 100 *arrow_height = static_cast<int>(arrow_target_height * scale_factor);
81 if (animation.is_animating()) { 101 if (animation.is_animating()) {
82 *arrow_half_width = static_cast<int>( 102 *arrow_half_width = static_cast<int>(
83 std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) * 103 std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) *
84 scale_factor); 104 scale_factor);
85 } else { 105 } else {
86 // When the infobar is not animating (i.e. fully open), we set the 106 // When the infobar is not animating (i.e. fully open), we set the
87 // half-width to be proportionally the same distance between its default and 107 // half-width to be proportionally the same distance between its default and
88 // maximum values as the height is between its. 108 // maximum values as the height is between its.
89 *arrow_half_width = kDefaultArrowTargetHalfWidth + 109 *arrow_half_width =
90 ((kMaximumArrowTargetHalfWidth - kDefaultArrowTargetHalfWidth) * 110 GetDefaultArrowTargetHalfWidth() +
111 ((kMaximumArrowTargetHalfWidth - GetDefaultArrowTargetHalfWidth()) *
91 ((*arrow_height - kDefaultArrowTargetHeight) / 112 ((*arrow_height - kDefaultArrowTargetHeight) /
92 (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight))); 113 (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight)));
93 } 114 }
94 // Add pixels for the stroke, if the arrow is to be visible at all. Without 115 // Add pixels for the stroke, if the arrow is to be visible at all. Without
95 // this, changing the arrow height from 0 to kSeparatorLineHeight would 116 // this, changing the arrow height from 0 to kSeparatorLineHeight would
96 // produce no visible effect, because the stroke would paint atop the divider 117 // produce no visible effect, because the stroke would paint atop the divider
97 // line above the infobar. 118 // line above the infobar.
98 if (*arrow_height) 119 if (*arrow_height)
99 *arrow_height += kSeparatorLineHeight; 120 *arrow_height += kSeparatorLineHeight;
100 121
101 int target_height = bar_target_height != -1 122 int target_height = bar_target_height != -1
102 ? bar_target_height 123 ? bar_target_height
103 : ui::MaterialDesignController::IsModeMaterial() 124 : ui::MaterialDesignController::IsModeMaterial()
104 ? kDefaultBarTargetHeightMd 125 ? kDefaultBarTargetHeightMd
105 : kDefaultBarTargetHeight; 126 : kDefaultBarTargetHeight;
106 *bar_height = animation.CurrentValueBetween(0, target_height); 127 *bar_height = animation.CurrentValueBetween(0, target_height);
107 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698