summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
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
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')
-rw-r--r--chrome/browser/views/bookmark_bar_instructions_view.cc106
-rw-r--r--chrome/browser/views/bookmark_bar_instructions_view.h63
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc14
-rw-r--r--chrome/browser/views/bookmark_bar_view.h14
-rw-r--r--chrome/browser/views/importer_view.cc20
-rw-r--r--chrome/browser/views/importer_view.h7
-rw-r--r--chrome/browser/views/options/content_page_view.cc2
7 files changed, 206 insertions, 20 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);
+}
diff --git a/chrome/browser/views/bookmark_bar_instructions_view.h b/chrome/browser/views/bookmark_bar_instructions_view.h
new file mode 100644
index 0000000..4f148d5
--- /dev/null
+++ b/chrome/browser/views/bookmark_bar_instructions_view.h
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef CHROME_BROWSER_VIEWS_BOOKMARK_BAR_INSTRUCTIONS_VIEW_H_
+#define CHROME_BROWSER_VIEWS_BOOKMARK_BAR_INSTRUCTIONS_VIEW_H_
+
+#include "views/view.h"
+#include "views/controls/link.h"
+
+namespace views {
+class Label;
+class Link;
+}
+
+// BookmarkBarInstructionsView is a child of the bookmark bar that is visible
+// when the user has no bookmarks on the bookmark bar.
+// BookmarkBarInstructionsView shows a description of the bookmarks bar along
+// with a link to import bookmarks. Clicking the link results in notifying the
+// delegate.
+class BookmarkBarInstructionsView : public views::View,
+ public views::LinkController {
+ public:
+ // The delegate is notified once the user clicks on the link to import
+ // bookmarks.
+ class Delegate {
+ public:
+ virtual void ShowImportDialog() = 0;
+ };
+
+ explicit BookmarkBarInstructionsView(Delegate* delegate);
+
+ // View overrides.
+ virtual gfx::Size GetPreferredSize();
+ virtual void Layout();
+ virtual void ThemeChanged();
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child);
+
+ // LinkController.
+ virtual void LinkActivated(views::Link* source, int event_flags);
+
+ private:
+ void UpdateColors();
+
+ Delegate* delegate_;
+
+ views::Label* instructions_;
+ views::Link* import_link_;
+
+ // The baseline of the child views. This is -1 if none of the views support a
+ // baseline.
+ int baseline_;
+
+ // Have the colors of the child views been updated? This is initially false
+ // and set to true once we have a valid ThemeProvider.
+ bool updated_colors_;
+
+ DISALLOW_COPY_AND_ASSIGN(BookmarkBarInstructionsView);
+};
+
+#endif // CHROME_BROWSER_VIEWS_BOOKMARK_BAR_INSTRUCTIONS_VIEW_H_
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 3b95041..6f57092d 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/views/bookmark_context_menu.h"
#include "chrome/browser/views/event_utils.h"
#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/views/importer_view.h"
#include "chrome/browser/views/location_bar_view.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/page_transition_types.h"
@@ -860,6 +861,13 @@ void BookmarkBarView::GetAnchorPositionAndStartIndexForButton(
*start_index = 0;
}
+void BookmarkBarView::ShowImportDialog() {
+ views::Window::CreateChromeWindow(
+ GetWindow()->GetNativeWindow(),
+ gfx::Rect(),
+ new ImporterView(profile_, FAVORITES))->Show();
+}
+
void BookmarkBarView::Init() {
// Note that at this point we're not in a hierarchy so GetThemeProvider() will
// return NULL. When we're inserted into a hierarchy, we'll call
@@ -885,10 +893,7 @@ void BookmarkBarView::Init() {
l10n_util::GetString(IDS_ACCNAME_SEPARATOR));
AddChildView(bookmarks_separator_view_);
- instructions_ = new views::Label(
- l10n_util::GetString(IDS_BOOKMARKS_NO_ITEMS),
- rb.GetFont(ResourceBundle::BaseFont));
-
+ instructions_ = new BookmarkBarInstructionsView(this);
AddChildView(instructions_);
SetContextMenuController(this);
@@ -1536,7 +1541,6 @@ void BookmarkBarView::UpdateColors() {
return;
SkColor text_color =
theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
- instructions_->SetColor(text_color);
for (int i = 0; i < GetBookmarkButtonCount(); ++i)
GetBookmarkButton(i)->SetEnabledColor(text_color);
other_bookmarked_button()->SetEnabledColor(text_color);
diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h
index 49ac37f..92efeb8 100644
--- a/chrome/browser/views/bookmark_bar_view.h
+++ b/chrome/browser/views/bookmark_bar_view.h
@@ -8,8 +8,8 @@
#include "app/slide_animation.h"
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
-#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/sync/profile_sync_service.h"
+#include "chrome/browser/views/bookmark_bar_instructions_view.h"
#include "chrome/browser/views/bookmark_menu_controller_views.h"
#include "chrome/browser/views/detachable_toolbar_view.h"
#include "chrome/common/notification_registrar.h"
@@ -22,7 +22,6 @@ class PrefService;
namespace views {
class CustomButton;
-class Label;
class MenuButton;
class MenuItemView;
class TextButton;
@@ -44,7 +43,8 @@ class BookmarkBarView : public DetachableToolbarView,
public views::ContextMenuController,
public views::DragController,
public AnimationDelegate,
- public BookmarkMenuController::Observer {
+ public BookmarkMenuController::Observer,
+ public BookmarkBarInstructionsView::Delegate {
friend class ShowFolderMenuTask;
public:
@@ -204,6 +204,9 @@ class BookmarkBarView : public DetachableToolbarView,
views::MenuItemView::AnchorPosition* anchor,
int* start_index);
+ // BookmarkBarInstructionsView::Delegate.
+ virtual void ShowImportDialog();
+
// Maximum size of buttons on the bookmark bar.
static const int kMaxButtonWidth;
@@ -463,8 +466,9 @@ class BookmarkBarView : public DetachableToolbarView,
// Visible if not all the bookmark buttons fit.
views::MenuButton* overflow_button_;
- // If no bookmarks are visible, we show some text explaining the bar.
- views::Label* instructions_;
+ // BookmarkBarInstructionsView that is visible if there are no bookmarks on
+ // the bookmark bar.
+ views::View* instructions_;
ButtonSeparatorView* bookmarks_separator_view_;
diff --git a/chrome/browser/views/importer_view.cc b/chrome/browser/views/importer_view.cc
index 5df68ef..12636c8 100644
--- a/chrome/browser/views/importer_view.cc
+++ b/chrome/browser/views/importer_view.cc
@@ -25,12 +25,12 @@ namespace browser {
void ShowImporterView(views::Widget* parent,
Profile* profile) {
views::Window::CreateChromeWindow(parent->GetNativeView(), gfx::Rect(),
- new ImporterView(profile))->Show();
+ new ImporterView(profile, ALL))->Show();
}
} // namespace browser
-ImporterView::ImporterView(Profile* profile)
+ImporterView::ImporterView(Profile* profile, int initial_state)
: import_from_label_(NULL),
profile_combobox_(NULL),
import_items_label_(NULL),
@@ -39,7 +39,8 @@ ImporterView::ImporterView(Profile* profile)
passwords_checkbox_(NULL),
search_engines_checkbox_(NULL),
profile_(profile),
- importer_host_(new ImporterHost()) {
+ importer_host_(new ImporterHost()),
+ initial_state_(initial_state) {
DCHECK(profile);
SetupControl();
}
@@ -59,14 +60,17 @@ void ImporterView::SetupControl() {
new views::Label(l10n_util::GetString(IDS_IMPORT_ITEMS_LABEL));
history_checkbox_ =
- InitCheckbox(l10n_util::GetString(IDS_IMPORT_HISTORY_CHKBOX), true);
+ InitCheckbox(l10n_util::GetString(IDS_IMPORT_HISTORY_CHKBOX),
+ (initial_state_ & HISTORY) != 0);
favorites_checkbox_ =
- InitCheckbox(l10n_util::GetString(IDS_IMPORT_FAVORITES_CHKBOX), true);
+ InitCheckbox(l10n_util::GetString(IDS_IMPORT_FAVORITES_CHKBOX),
+ (initial_state_ & FAVORITES) != 0);
passwords_checkbox_ =
- InitCheckbox(l10n_util::GetString(IDS_IMPORT_PASSWORDS_CHKBOX), true);
+ InitCheckbox(l10n_util::GetString(IDS_IMPORT_PASSWORDS_CHKBOX),
+ (initial_state_ & PASSWORDS) != 0);
search_engines_checkbox_ =
InitCheckbox(l10n_util::GetString(IDS_IMPORT_SEARCH_ENGINES_CHKBOX),
- true);
+ (initial_state_ & SEARCH_ENGINES) != 0);
// Arranges controls by using GridLayout.
const int column_set_id = 0;
@@ -154,7 +158,7 @@ int ImporterView::GetItemCount() {
DCHECK(importer_host_.get());
int item_count = importer_host_->GetAvailableProfileCount();
if (checkbox_items_.size() < static_cast<size_t>(item_count))
- checkbox_items_.resize(item_count, ALL);
+ checkbox_items_.resize(item_count, initial_state_);
return item_count;
}
diff --git a/chrome/browser/views/importer_view.h b/chrome/browser/views/importer_view.h
index 88a07cb..ac1bc20 100644
--- a/chrome/browser/views/importer_view.h
+++ b/chrome/browser/views/importer_view.h
@@ -30,7 +30,9 @@ class ImporterView : public views::View,
public views::Combobox::Listener,
public ImportObserver {
public:
- explicit ImporterView(Profile* profile);
+ // Creates a new ImporterView. |initial_state| is a bitmask of ImportItems.
+ // Each checkbox for the bits in |initial_state| is checked.
+ ImporterView(Profile* profile, int initial_state);
virtual ~ImporterView();
// Overridden from views::View.
@@ -88,6 +90,9 @@ class ImporterView : public views::View,
// selected item in the combo-box.
std::vector<uint16> checkbox_items_;
+ // Initial state of the checkbox_items_.
+ uint16 initial_state_;
+
Profile* profile_;
DISALLOW_EVIL_CONSTRUCTORS(ImporterView);
diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc
index 3189919..686d6498 100644
--- a/chrome/browser/views/options/content_page_view.cc
+++ b/chrome/browser/views/options/content_page_view.cc
@@ -113,7 +113,7 @@ void ContentPageView::ButtonPressed(
views::Window::CreateChromeWindow(
GetWindow()->GetNativeWindow(),
gfx::Rect(),
- new ImporterView(profile()))->Show();
+ new ImporterView(profile(), ALL))->Show();
} else if (sender == clear_data_button_) {
views::Window::CreateChromeWindow(
GetWindow()->GetNativeWindow(),