summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/location_bar/icon_label_bubble_view.cc
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 17:57:17 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 17:57:17 +0000
commit265ccd99339c4a7bcdc3c163692f9344fe9e2ae5 (patch)
treec07c81496c8b66a1d9f55bc7d11ac842151b3e25 /chrome/browser/views/location_bar/icon_label_bubble_view.cc
parent24e2b10503e5f54ce5b4beb96a6403c3a8e7e62f (diff)
downloadchromium_src-265ccd99339c4a7bcdc3c163692f9344fe9e2ae5.zip
chromium_src-265ccd99339c4a7bcdc3c163692f9344fe9e2ae5.tar.gz
chromium_src-265ccd99339c4a7bcdc3c163692f9344fe9e2ae5.tar.bz2
Relanding http://codereview.chromium.org/1746009/show
(fixed the ChromeOS build). The app launcher now uses the location bar (instead of the autocomplete edit), so it has "tab to search" and the icons on the left side, Also split location_bar_view.cc so that every inner-class gets its own .h and .cc file. BUG=None TEST=Make sure the location bar works as expected (tab to search, bookmark star, page actions...). Open the app launcher, make sure "tab to search" works as expected. Review URL: http://codereview.chromium.org/1792010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45957 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/location_bar/icon_label_bubble_view.cc')
-rw-r--r--chrome/browser/views/location_bar/icon_label_bubble_view.cc72
1 files changed, 72 insertions, 0 deletions
diff --git a/chrome/browser/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/views/location_bar/icon_label_bubble_view.cc
new file mode 100644
index 0000000..c40acff
--- /dev/null
+++ b/chrome/browser/views/location_bar/icon_label_bubble_view.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/views/location_bar/icon_label_bubble_view.h"
+
+#include "app/resource_bundle.h"
+#include "chrome/browser/views/location_bar/location_bar_view.h"
+#include "gfx/canvas.h"
+#include "views/controls/image_view.h"
+#include "views/controls/label.h"
+
+// Amount to offset the image.
+static const int kImageOffset = 1;
+
+// Amount to offset the label from the image.
+static const int kLabelOffset = 3;
+
+// Amount of padding after the label.
+static const int kLabelPadding = 4;
+
+IconLabelBubbleView::IconLabelBubbleView(const int background_images[],
+ int contained_image,
+ const SkColor& color)
+ : background_painter_(background_images) {
+ image_ = new views::ImageView();
+ AddChildView(image_);
+ image_->SetImage(
+ ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image));
+ label_ = new views::Label();
+ AddChildView(label_);
+ label_->SetColor(color);
+}
+
+IconLabelBubbleView::~IconLabelBubbleView() {
+}
+
+void IconLabelBubbleView::SetFont(const gfx::Font& font) {
+ label_->SetFont(font);
+}
+
+void IconLabelBubbleView::SetLabel(const std::wstring& label) {
+ label_->SetText(label);
+}
+
+void IconLabelBubbleView::Paint(gfx::Canvas* canvas) {
+ int y_offset = (GetParent()->height() - height()) / 2;
+ canvas->TranslateInt(0, y_offset);
+ background_painter_.Paint(width(), height(), canvas);
+ canvas->TranslateInt(0, -y_offset);
+}
+
+gfx::Size IconLabelBubbleView::GetPreferredSize() {
+ gfx::Size size(GetNonLabelSize());
+ size.Enlarge(label_->GetPreferredSize().width(), 0);
+ return size;
+}
+
+void IconLabelBubbleView::Layout() {
+ image_->SetBounds(kImageOffset, 0, image_->GetPreferredSize().width(),
+ height());
+ gfx::Size label_size(label_->GetPreferredSize());
+ label_->SetBounds(image_->x() + image_->width() + kLabelOffset,
+ (height() - label_size.height()) / 2, label_size.width(),
+ label_size.height());
+}
+
+gfx::Size IconLabelBubbleView::GetNonLabelSize() {
+ return gfx::Size(kImageOffset + image_->GetPreferredSize().width() +
+ kLabelOffset + kLabelPadding, background_painter_.height());
+}
+