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

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

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

Powered by Google App Engine
This is Rietveld 408576698