summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/bookmark_bar_instructions_view.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 21:19:07 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 21:19:07 +0000
commita136016faff78780a4776c03e252e51d2f7cae37 (patch)
treeffbc1550c4275cd674f11410e15639f71daa67cf /chrome/browser/views/bookmark_bar_instructions_view.cc
parent9acc48601ea4aff4e5ec977c0dd089e887ba5ffd (diff)
downloadchromium_src-a136016faff78780a4776c03e252e51d2f7cae37.zip
chromium_src-a136016faff78780a4776c03e252e51d2f7cae37.tar.gz
chromium_src-a136016faff78780a4776c03e252e51d2f7cae37.tar.bz2
Adds link to bookmark bar that when clicked imports bookmarks. I also
added support for baselines to GridLayout. BUG=4374 TEST=On a new profile make sure the bookmark bar has a link to import bookmarks, click the link and make sure you can import your bookmarks. Review URL: http://codereview.chromium.org/440029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33336 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/bookmark_bar_instructions_view.cc')
-rw-r--r--chrome/browser/views/bookmark_bar_instructions_view.cc106
1 files changed, 106 insertions, 0 deletions
diff --git a/chrome/browser/views/bookmark_bar_instructions_view.cc b/chrome/browser/views/bookmark_bar_instructions_view.cc
new file mode 100644
index 0000000..3b38001
--- /dev/null
+++ b/chrome/browser/views/bookmark_bar_instructions_view.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2009 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/bookmark_bar_instructions_view.h"
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "chrome/browser/browser_theme_provider.h"
+#include "chrome/browser/defaults.h"
+#include "grit/generated_resources.h"
+#include "views/controls/label.h"
+
+using views::View;
+
+// Horizontal padding, in pixels, between the link and label.
+static const int kViewPadding = 6;
+
+BookmarkBarInstructionsView::BookmarkBarInstructionsView(Delegate* delegate)
+ : delegate_(delegate),
+ instructions_(NULL),
+ import_link_(NULL),
+ baseline_(-1),
+ updated_colors_(false) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+
+ instructions_ = new views::Label(
+ l10n_util::GetString(IDS_BOOKMARKS_NO_ITEMS));
+ AddChildView(instructions_);
+
+ if (browser_defaults::kShowImportOnBookmarkBar) {
+ import_link_ = new views::Link(
+ l10n_util::GetString(IDS_BOOKMARK_BAR_IMPORT_LINK));
+ // We don't want the link to alter tab navigation.
+ import_link_->SetFocusable(false);
+ import_link_->SetController(this);
+ AddChildView(import_link_);
+ }
+}
+
+gfx::Size BookmarkBarInstructionsView::GetPreferredSize() {
+ int ascent = 0, descent = 0, height = 0, width = 0;
+ for (int i = 0; i < GetChildViewCount(); ++i) {
+ View* view = GetChildViewAt(i);
+ gfx::Size pref = view->GetPreferredSize();
+ int baseline = view->GetBaseline();
+ if (baseline != -1) {
+ ascent = std::max(ascent, baseline);
+ descent = std::max(descent, pref.height() - baseline);
+ } else {
+ height = std::max(pref.height(), height);
+ }
+ width += pref.width();
+ }
+ width += (GetChildViewCount() - 1) * kViewPadding;
+ if (ascent != 0)
+ height = std::max(ascent + descent, height);
+ return gfx::Size(width, height);
+}
+
+void BookmarkBarInstructionsView::Layout() {
+ int remaining_width = width();
+ int x = 0;
+ for (int i = 0; i < GetChildViewCount(); ++i) {
+ View* view = GetChildViewAt(i);
+ gfx::Size pref = view->GetPreferredSize();
+ int baseline = view->GetBaseline();
+ int y;
+ if (baseline != -1 && baseline_ != -1)
+ y = baseline_ - baseline;
+ else
+ y = (height() - pref.height()) / 2;
+ int view_width = std::min(remaining_width, pref.width());
+ view->SetBounds(x, y, view_width, pref.height());
+ x += view_width + kViewPadding;
+ remaining_width = std::max(0, width() - x);
+ }
+}
+
+void BookmarkBarInstructionsView::ThemeChanged() {
+ UpdateColors();
+}
+
+void BookmarkBarInstructionsView::ViewHierarchyChanged(bool is_add,
+ View* parent,
+ View* child) {
+ if (!updated_colors_ && is_add && GetWidget())
+ UpdateColors();
+}
+
+void BookmarkBarInstructionsView::LinkActivated(views::Link* source,
+ int event_flags) {
+ delegate_->ShowImportDialog();
+}
+
+void BookmarkBarInstructionsView::UpdateColors() {
+ // We don't always have a theme provider (ui tests, for example).
+ const ThemeProvider* theme_provider = GetThemeProvider();
+ if (!theme_provider)
+ return;
+ updated_colors_ = true;
+ SkColor text_color =
+ theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
+ instructions_->SetColor(text_color);
+ import_link_->SetColor(text_color);
+}