OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/location_bar/icon_label_bubble_view.h" | 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/layout_constants.h" | 8 #include "chrome/browser/ui/layout_constants.h" |
9 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 9 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
10 #include "ui/base/material_design/material_design_controller.h" | 10 #include "ui/base/material_design/material_design_controller.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 const int image_width = image_->GetPreferredSize().width(); | 113 const int image_width = image_->GetPreferredSize().width(); |
114 return image_width ? (image_width + GetInternalSpacing()) : 0; | 114 return image_width ? (image_width + GetInternalSpacing()) : 0; |
115 } | 115 } |
116 | 116 |
117 gfx::Size IconLabelBubbleView::GetPreferredSize() const { | 117 gfx::Size IconLabelBubbleView::GetPreferredSize() const { |
118 // Height will be ignored by the LocationBarView. | 118 // Height will be ignored by the LocationBarView. |
119 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); | 119 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); |
120 } | 120 } |
121 | 121 |
122 void IconLabelBubbleView::Layout() { | 122 void IconLabelBubbleView::Layout() { |
123 // Compute the label bounds. The label gets whatever size is left over after | 123 // Compute the image bounds. In non-MD, the leading padding depends on |
124 // accounting for the preferred image width and padding amounts. Note that if | |
125 // the label has zero size it doesn't actually matter what we compute its X | |
126 // value to be, since it won't be visible, so the X value can be "wrong" | |
127 // compared to where the right edge of the image is computed to be below. | |
128 // This means doing this layout doesn't doesn't depend on any of the layout | |
129 // below. That layout, however, may need for this layout to have already | |
130 // happened, since the value of ShouldShowBackground() we read below may | |
131 // depend on whether the label has nonzero size. Therefore, we do this first. | |
132 const int label_x = GetOuterPadding(true) + GetImageAndPaddingWidth(); | |
133 const int label_width = | |
134 std::max(0, width() - label_x - GetOuterPadding(false)); | |
135 label_->SetBounds(label_x, 0, label_width, height()); | |
136 | |
137 // Now compute the image bounds. In non-MD, the leading padding depends on | |
138 // whether this is an extension icon, since extension icons and | 124 // whether this is an extension icon, since extension icons and |
139 // Chrome-provided icons are different sizes. In MD, these sizes are the | 125 // Chrome-provided icons are different sizes. In MD, these sizes are the |
140 // same, so it's not necessary to handle the two types differently. | 126 // same, so it's not necessary to handle the two types differently. |
141 const bool icon_has_enough_padding = | 127 const bool icon_has_enough_padding = |
142 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); | 128 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); |
varkha
2016/03/30 03:43:19
nit: Do you still need the check for IsModeMateria
Peter Kasting
2016/03/30 03:57:55
Yes, because in the next change set that will no l
| |
143 int image_x = GetOuterPadding(icon_has_enough_padding); | 129 int image_x = GetOuterPadding(icon_has_enough_padding); |
144 int bubble_trailing_padding = GetOuterPadding(false); | 130 int bubble_trailing_padding = GetOuterPadding(false); |
145 | 131 |
146 // If ShouldShowBackground() is true, then either we show a background in the | 132 // If ShouldShowBackground() is true, then either we show a background in the |
147 // steady state, or we're not yet in the last portion of the animation. In | 133 // steady state, or we're not yet in the last portion of the animation. In |
148 // these cases, we leave the leading and trailing padding alone; we don't want | 134 // these cases, we leave the leading and trailing padding alone; we don't want |
149 // to let the image overlap the edge of the background, as this looks glitchy. | 135 // to let the image overlap the edge of the background, as this looks glitchy. |
150 // If this is false, however, then we're only showing the image, and either | 136 // If this is false, however, then we're only showing the image, and either |
151 // the view width is the image width, or it's animating downwards and getting | 137 // the view width is the image width, or it's animating downwards and getting |
152 // close to it. In these cases, we want to shrink the trailing padding first, | 138 // close to it. In these cases, we want to shrink the trailing padding first, |
153 // so the image slides all the way to the trailing edge before slowing or | 139 // so the image slides all the way to the trailing edge before slowing or |
154 // stopping; then we want to shrink the leading padding down to zero. | 140 // stopping; then we want to shrink the leading padding down to zero. |
155 const int image_preferred_width = image_->GetPreferredSize().width(); | 141 const int image_preferred_width = image_->GetPreferredSize().width(); |
156 if (!ShouldShowBackground()) { | 142 if (!ShouldShowBackground()) { |
157 image_x = std::min(image_x, width() - image_preferred_width); | 143 image_x = std::min(image_x, width() - image_preferred_width); |
158 bubble_trailing_padding = std::min( | 144 bubble_trailing_padding = std::min( |
159 bubble_trailing_padding, width() - image_preferred_width - image_x); | 145 bubble_trailing_padding, width() - image_preferred_width - image_x); |
160 } | 146 } |
161 | 147 |
162 // Now that we've computed the padding values, give the image all the | 148 // Now that we've computed the padding values, give the image all the |
163 // remaining width. This will be less than the image's preferred width during | 149 // remaining width. This will be less than the image's preferred width during |
164 // the first portion of the animation; during the very beginning there may not | 150 // the first portion of the animation; during the very beginning there may not |
165 // be enough room to show the image at all. | 151 // be enough room to show the image at all. |
166 const int image_width = | 152 const int image_width = |
167 std::min(image_preferred_width, | 153 std::min(image_preferred_width, |
168 std::max(0, width() - image_x - bubble_trailing_padding)); | 154 std::max(0, width() - image_x - bubble_trailing_padding)); |
169 image_->SetBounds(image_x, 0, image_width, height()); | 155 image_->SetBounds(image_x, 0, image_width, height()); |
156 | |
157 // Compute the label bounds. The label gets whatever size is left over after | |
158 // accounting for the preferred image width and padding amounts. Note that if | |
159 // the label has zero size it doesn't actually matter what we compute its X | |
160 // value to be, since it won't be visible. | |
161 const int label_x = image_x + GetImageAndPaddingWidth(); | |
162 const int label_width = | |
163 std::max(0, width() - label_x - bubble_trailing_padding); | |
164 label_->SetBounds(label_x, 0, label_width, height()); | |
170 } | 165 } |
171 | 166 |
172 void IconLabelBubbleView::OnNativeThemeChanged( | 167 void IconLabelBubbleView::OnNativeThemeChanged( |
173 const ui::NativeTheme* native_theme) { | 168 const ui::NativeTheme* native_theme) { |
174 label_->SetEnabledColor(GetTextColor()); | 169 label_->SetEnabledColor(GetTextColor()); |
175 | 170 |
176 if (!ui::MaterialDesignController::IsModeMaterial()) | 171 if (!ui::MaterialDesignController::IsModeMaterial()) |
177 return; | 172 return; |
178 | 173 |
179 bool inverted = color_utils::IsDark(GetParentBackgroundColor()); | 174 bool inverted = color_utils::IsDark(GetParentBackgroundColor()); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | 271 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
277 if (!ShouldShowBackground()) | 272 if (!ShouldShowBackground()) |
278 return; | 273 return; |
279 if (background_painter_) { | 274 if (background_painter_) { |
280 views::Painter::PaintPainterAt(canvas, background_painter_.get(), | 275 views::Painter::PaintPainterAt(canvas, background_painter_.get(), |
281 GetContentsBounds()); | 276 GetContentsBounds()); |
282 } | 277 } |
283 if (background()) | 278 if (background()) |
284 background()->Paint(canvas, this); | 279 background()->Paint(canvas, this); |
285 } | 280 } |
OLD | NEW |