| 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 9 #include "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/views/controls/image_view.h" | 12 #include "ui/views/controls/image_view.h" |
| 13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
| 14 | 14 |
| 15 namespace { |
| 16 |
| 15 // Amount of padding at the edges of the bubble. | 17 // Amount of padding at the edges of the bubble. |
| 16 static const int kBubbleOuterPadding = LocationBarView::kEdgeItemPadding - | 18 // |
| 17 LocationBarView::kBubbleHorizontalPadding; | 19 // This can't be statically initialized because |
| 20 // LocationBarView::GetEdgeItemPadding() depends on whether we are |
| 21 // using desktop or touch layout, and this in turn depends on the |
| 22 // command line. |
| 23 int GetBubbleOuterPadding() { |
| 24 return LocationBarView::GetEdgeItemPadding() - |
| 25 LocationBarView::kBubbleHorizontalPadding; |
| 26 } |
| 18 | 27 |
| 19 // Amount of padding after the label. | 28 // Amount of padding after the label. |
| 20 static const int kLabelPadding = 5; | 29 const int kLabelPadding = 5; |
| 30 |
| 31 } // namespace |
| 21 | 32 |
| 22 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], | 33 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], |
| 23 int contained_image, | 34 int contained_image, |
| 24 SkColor color) | 35 SkColor color) |
| 25 : background_painter_(background_images), | 36 : background_painter_(background_images), |
| 26 is_extension_icon_(false) { | 37 is_extension_icon_(false) { |
| 27 image_ = new views::ImageView(); | 38 image_ = new views::ImageView(); |
| 28 image_->SetImage( | 39 image_->SetImage( |
| 29 ui::ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); | 40 ui::ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); |
| 30 AddChildView(image_); | 41 AddChildView(image_); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 54 background_painter_.Paint(canvas, size()); | 65 background_painter_.Paint(canvas, size()); |
| 55 } | 66 } |
| 56 | 67 |
| 57 gfx::Size IconLabelBubbleView::GetPreferredSize() { | 68 gfx::Size IconLabelBubbleView::GetPreferredSize() { |
| 58 gfx::Size size(GetNonLabelSize()); | 69 gfx::Size size(GetNonLabelSize()); |
| 59 size.Enlarge(label_->GetPreferredSize().width(), 0); | 70 size.Enlarge(label_->GetPreferredSize().width(), 0); |
| 60 return size; | 71 return size; |
| 61 } | 72 } |
| 62 | 73 |
| 63 void IconLabelBubbleView::Layout() { | 74 void IconLabelBubbleView::Layout() { |
| 64 image_->SetBounds(kBubbleOuterPadding + | 75 image_->SetBounds(GetBubbleOuterPadding() + |
| 65 (is_extension_icon_ ? LocationBarView::kIconInternalPadding : 0), 0, | 76 (is_extension_icon_ ? LocationBarView::kIconInternalPadding : 0), 0, |
| 66 image_->GetPreferredSize().width(), height()); | 77 image_->GetPreferredSize().width(), height()); |
| 67 const int label_height = label_->GetPreferredSize().height(); | 78 const int label_height = label_->GetPreferredSize().height(); |
| 68 label_->SetBounds(GetPreLabelWidth(), (height() - label_height) / 2, | 79 label_->SetBounds(GetPreLabelWidth(), (height() - label_height) / 2, |
| 69 width() - GetNonLabelWidth(), label_height); | 80 width() - GetNonLabelWidth(), label_height); |
| 70 } | 81 } |
| 71 | 82 |
| 72 void IconLabelBubbleView::SetElideInMiddle(bool elide_in_middle) { | 83 void IconLabelBubbleView::SetElideInMiddle(bool elide_in_middle) { |
| 73 label_->SetElideInMiddle(elide_in_middle); | 84 label_->SetElideInMiddle(elide_in_middle); |
| 74 } | 85 } |
| 75 | 86 |
| 76 gfx::Size IconLabelBubbleView::GetNonLabelSize() const { | 87 gfx::Size IconLabelBubbleView::GetNonLabelSize() const { |
| 77 return gfx::Size(GetNonLabelWidth(), background_painter_.height()); | 88 return gfx::Size(GetNonLabelWidth(), background_painter_.height()); |
| 78 } | 89 } |
| 79 | 90 |
| 80 int IconLabelBubbleView::GetPreLabelWidth() const { | 91 int IconLabelBubbleView::GetPreLabelWidth() const { |
| 81 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 92 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 82 return kBubbleOuterPadding + rb.GetBitmapNamed(IDR_OMNIBOX_SEARCH)->width() + | 93 return GetBubbleOuterPadding() + |
| 83 LocationBarView::kItemPadding; | 94 rb.GetBitmapNamed(IDR_OMNIBOX_SEARCH)->width() + |
| 95 LocationBarView::GetItemPadding(); |
| 84 } | 96 } |
| 85 | 97 |
| 86 int IconLabelBubbleView::GetNonLabelWidth() const { | 98 int IconLabelBubbleView::GetNonLabelWidth() const { |
| 87 return GetPreLabelWidth() + kBubbleOuterPadding; | 99 return GetPreLabelWidth() + GetBubbleOuterPadding(); |
| 88 } | 100 } |
| OLD | NEW |