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(); |
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 |
(...skipping 12 matching lines...) Expand all Loading... | |
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); | |
Peter Kasting
2016/03/25 10:13:05
Despite using |image_x| and |bubble_trailing_paddi
| |
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | 268 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
274 if (!ShouldShowBackground()) | 269 if (!ShouldShowBackground()) |
275 return; | 270 return; |
276 if (background_painter_) { | 271 if (background_painter_) { |
277 views::Painter::PaintPainterAt(canvas, background_painter_.get(), | 272 views::Painter::PaintPainterAt(canvas, background_painter_.get(), |
278 GetContentsBounds()); | 273 GetContentsBounds()); |
279 } | 274 } |
280 if (background()) | 275 if (background()) |
281 background()->Paint(canvas, this); | 276 background()->Paint(canvas, this); |
282 } | 277 } |
OLD | NEW |