| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 int IconLabelBubbleView::GetImageAndPaddingWidth() const { | 112 int IconLabelBubbleView::GetImageAndPaddingWidth() const { |
| 113 return image_->GetPreferredSize().width() + GetInternalSpacing(); | 113 return image_->GetPreferredSize().width() + GetInternalSpacing(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 gfx::Size IconLabelBubbleView::GetPreferredSize() const { | 116 gfx::Size IconLabelBubbleView::GetPreferredSize() const { |
| 117 // Height will be ignored by the LocationBarView. | 117 // Height will be ignored by the LocationBarView. |
| 118 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); | 118 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void IconLabelBubbleView::Layout() { | 121 void IconLabelBubbleView::Layout() { |
| 122 // Compute the label bounds. The label gets whatever size is left over after | 122 // Compute the image bounds. In non-MD, the leading padding depends on |
| 123 // accounting for the preferred image width and padding amounts. Note that if | |
| 124 // the label has zero size it doesn't actually matter what we compute its X | |
| 125 // value to be, since it won't be visible, so the X value can be "wrong" | |
| 126 // compared to where the right edge of the image is computed to be below. | |
| 127 // This means doing this layout doesn't doesn't depend on any of the layout | |
| 128 // below. That layout, however, may need for this layout to have already | |
| 129 // happened, since the value of ShouldShowBackground() we read below may | |
| 130 // depend on whether the label has nonzero size. Therefore, we do this first. | |
| 131 const int label_x = GetOuterPadding(true) + GetImageAndPaddingWidth(); | |
| 132 const int label_width = | |
| 133 std::max(0, width() - label_x - GetOuterPadding(false)); | |
| 134 label_->SetBounds(label_x, 0, label_width, height()); | |
| 135 | |
| 136 // Now compute the image bounds. In non-MD, the leading padding depends on | |
| 137 // whether this is an extension icon, since extension icons and | 123 // whether this is an extension icon, since extension icons and |
| 138 // Chrome-provided icons are different sizes. In MD, these sizes are the | 124 // Chrome-provided icons are different sizes. In MD, these sizes are the |
| 139 // same, so it's not necessary to handle the two types differently. | 125 // same, so it's not necessary to handle the two types differently. |
| 140 const bool icon_has_enough_padding = | 126 const bool icon_has_enough_padding = |
| 141 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); | 127 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); |
| 142 int image_x = GetOuterPadding(icon_has_enough_padding); | 128 int image_x = GetOuterPadding(icon_has_enough_padding); |
| 143 int bubble_trailing_padding = GetOuterPadding(false); | 129 int bubble_trailing_padding = GetOuterPadding(false); |
| 144 | 130 |
| 145 // If ShouldShowBackground() is true, then either we show a background in the | 131 // If ShouldShowBackground() is true, then either we show a background in the |
| 146 // steady state, or we're not yet in the last portion of the animation. In | 132 // steady state, or we're not yet in the last portion of the animation. In |
| (...skipping 12 matching lines...) Expand all Loading... |
| 159 } | 145 } |
| 160 | 146 |
| 161 // Now that we've computed the padding values, give the image all the | 147 // Now that we've computed the padding values, give the image all the |
| 162 // remaining width. This will be less than the image's preferred width during | 148 // remaining width. This will be less than the image's preferred width during |
| 163 // the first portion of the animation; during the very beginning there may not | 149 // the first portion of the animation; during the very beginning there may not |
| 164 // be enough room to show the image at all. | 150 // be enough room to show the image at all. |
| 165 const int image_width = | 151 const int image_width = |
| 166 std::min(image_preferred_width, | 152 std::min(image_preferred_width, |
| 167 std::max(0, width() - image_x - bubble_trailing_padding)); | 153 std::max(0, width() - image_x - bubble_trailing_padding)); |
| 168 image_->SetBounds(image_x, 0, image_width, height()); | 154 image_->SetBounds(image_x, 0, image_width, height()); |
| 155 |
| 156 // Compute the label bounds. The label gets whatever size is left over after |
| 157 // accounting for the preferred image width and padding amounts. Note that if |
| 158 // the label has zero size it doesn't actually matter what we compute its X |
| 159 // value to be, since it won't be visible. |
| 160 const int label_x = image_x + GetImageAndPaddingWidth(); |
| 161 const int label_width = |
| 162 std::max(0, width() - label_x - bubble_trailing_padding); |
| 163 label_->SetBounds(label_x, 0, label_width, height()); |
| 169 } | 164 } |
| 170 | 165 |
| 171 void IconLabelBubbleView::OnNativeThemeChanged( | 166 void IconLabelBubbleView::OnNativeThemeChanged( |
| 172 const ui::NativeTheme* native_theme) { | 167 const ui::NativeTheme* native_theme) { |
| 173 label_->SetEnabledColor(GetTextColor()); | 168 label_->SetEnabledColor(GetTextColor()); |
| 174 | 169 |
| 175 if (!ui::MaterialDesignController::IsModeMaterial()) | 170 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 176 return; | 171 return; |
| 177 | 172 |
| 178 bool inverted = color_utils::IsDark(GetParentBackgroundColor()); | 173 bool inverted = color_utils::IsDark(GetParentBackgroundColor()); |
| (...skipping 97 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 |