summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 02:09:52 +0000
committeravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 02:09:52 +0000
commit087e187238bafb30e6d28e2175e11fd56054e6d7 (patch)
treed90dcd0e4a6c875ace2ae93368f3a30dbc0a76e6 /chrome/browser
parent520b068ec2458f3441c84b6be13397d7a8daad4d (diff)
downloadchromium_src-087e187238bafb30e6d28e2175e11fd56054e6d7.zip
chromium_src-087e187238bafb30e6d28e2175e11fd56054e6d7.tar.gz
chromium_src-087e187238bafb30e6d28e2175e11fd56054e6d7.tar.bz2
Added Star button to compact navigation mode.
BUG=32326 TEST=Switch Chrome to compact mode by pressing Ctrl-Shift-C. Test that Star icon works. Review URL: http://codereview.chromium.org/543215 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/browser_view.cc14
-rw-r--r--chrome/browser/chromeos/browser_view.h2
-rw-r--r--chrome/browser/chromeos/compact_location_bar_host.cc7
-rw-r--r--chrome/browser/chromeos/compact_location_bar_host.h4
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.cc148
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.h22
-rw-r--r--chrome/browser/views/star_toggle.cc81
-rw-r--r--chrome/browser/views/star_toggle.h69
-rw-r--r--chrome/browser/views/toolbar_star_toggle.cc53
-rw-r--r--chrome/browser/views/toolbar_star_toggle.h33
-rw-r--r--chrome/browser/views/toolbar_view.cc27
11 files changed, 220 insertions, 240 deletions
diff --git a/chrome/browser/chromeos/browser_view.cc b/chrome/browser/chromeos/browser_view.cc
index b9c8bbd..cffeb67 100644
--- a/chrome/browser/chromeos/browser_view.cc
+++ b/chrome/browser/chromeos/browser_view.cc
@@ -27,6 +27,7 @@
#include "chrome/browser/views/tabs/tab_overview_types.h"
#include "chrome/browser/views/tabs/tab_strip.h"
#include "chrome/browser/views/toolbar_view.h"
+#include "chrome/browser/views/toolbar_star_toggle.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/x11_util.h"
#include "grit/generated_resources.h"
@@ -429,6 +430,19 @@ BaseTabStrip* BrowserView::CreateTabStrip(
return new ChromeosTabStrip(tab_strip_model, this);
}
+void BrowserView::SetStarredState(bool is_starred) {
+ ::BrowserView::SetStarredState(is_starred);
+ compact_location_bar_host_->GetStarButton()->SetToggled(is_starred);
+}
+
+void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
+ if (is_compact_style())
+ compact_location_bar_host_->GetStarButton()->ShowStarBubble(
+ url, !already_bookmarked);
+ else
+ ::BrowserView::ShowBookmarkBubble(url, already_bookmarked);
+}
+
// views::ButtonListener overrides.
void BrowserView::ButtonPressed(views::Button* sender,
const views::Event& event) {
diff --git a/chrome/browser/chromeos/browser_view.h b/chrome/browser/chromeos/browser_view.h
index 278e134..a8d0470 100644
--- a/chrome/browser/chromeos/browser_view.h
+++ b/chrome/browser/chromeos/browser_view.h
@@ -63,6 +63,8 @@ class BrowserView : public ::BrowserView,
virtual void ToggleCompactNavigationBar();
virtual views::LayoutManager* CreateLayoutManager() const;
virtual BaseTabStrip* CreateTabStrip(TabStripModel* tab_strip_model);
+ virtual void SetStarredState(bool is_starred);
+ virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
// views::ButtonListener overrides.
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc
index 56a2fc4..98d4325 100644
--- a/chrome/browser/chromeos/compact_location_bar_host.cc
+++ b/chrome/browser/chromeos/compact_location_bar_host.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/compact_location_bar_host.h"
+#include <algorithm>
+
#include "app/slide_animation.h"
#include "base/keyboard_codes.h"
#include "chrome/browser/browser.h"
@@ -19,6 +21,7 @@
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/tabs/tab.h"
#include "chrome/browser/views/tabs/tab_strip.h"
+#include "chrome/browser/views/toolbar_star_toggle.h"
#include "views/controls/scrollbar/native_scroll_bar.h"
#include "views/focus/external_focus_tracker.h"
#include "views/focus/view_storage.h"
@@ -259,6 +262,10 @@ void CompactLocationBarHost::SetEnabled(bool enabled) {
}
}
+ToolbarStarToggle* CompactLocationBarHost::GetStarButton() {
+ return GetClbView()->star_button();
+}
+
void CompactLocationBarHost::Show(bool a) {
MessageLoopForUI::current()->AddObserver(mouse_observer_.get());
DropdownBarHost::Show(a);
diff --git a/chrome/browser/chromeos/compact_location_bar_host.h b/chrome/browser/chromeos/compact_location_bar_host.h
index d386ac5..da1bb9c 100644
--- a/chrome/browser/chromeos/compact_location_bar_host.h
+++ b/chrome/browser/chromeos/compact_location_bar_host.h
@@ -16,6 +16,7 @@
class BrowserView;
class TabContents;
class Tab;
+class ToolbarStarToggle;
namespace chromeos {
@@ -60,6 +61,9 @@ class CompactLocationBarHost : public DropdownBarHost,
// Enable/disable the compact location bar.
void SetEnabled(bool enabled);
+ // Returns the star button for compact location bar.
+ ToolbarStarToggle* GetStarButton();
+
// Overridehden from DropdownBarhost.
virtual void Show(bool animate);
virtual void Hide(bool animate);
diff --git a/chrome/browser/chromeos/compact_location_bar_view.cc b/chrome/browser/chromeos/compact_location_bar_view.cc
index 16b00c4..ce9606b 100644
--- a/chrome/browser/chromeos/compact_location_bar_view.cc
+++ b/chrome/browser/chromeos/compact_location_bar_view.cc
@@ -8,42 +8,42 @@
#include <algorithm>
#include "app/l10n_util.h"
-#include "app/gfx/canvas.h"
-#include "app/resource_bundle.h"
+#include "app/drag_drop_types.h"
#include "base/gfx/point.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/bookmarks/bookmark_drag_data.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/chromeos/compact_location_bar_host.h"
+#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/view_ids.h"
-#include "chrome/browser/views/browser_actions_container.h"
#include "chrome/browser/views/event_utils.h"
#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/views/toolbar_star_toggle.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "views/background.h"
#include "views/controls/button/image_button.h"
#include "views/controls/native/native_view_host.h"
+#include "views/drag_utils.h"
#include "views/widget/widget.h"
#include "views/window/window.h"
namespace chromeos {
-const int kAutocompletePopupWidth = 700;
-const int kDefaultLocationEntryWidth = 250;
-const int kCompactLocationLeftRightMargin = 5;
-const int kEntryLeftMargin = 2;
-// TODO(oshima): ToolbarView gets this from background image's height;
-// Find out the right way, value for compact location bar.
-const int kDefaultLocationBarHeight = 34;
+
+const int kCompactLocationBarDefaultWidth = 700;
+const int kWidgetsSeparatorWidth = 2;
CompactLocationBarView::CompactLocationBarView(CompactLocationBarHost* host)
: DropdownBarView(host),
reload_(NULL),
- location_entry_view_(NULL),
- browser_actions_(NULL) {
+ star_(NULL) {
+ set_background(views::Background::CreateStandardPanelBackground());
SetFocusable(true);
}
@@ -60,7 +60,6 @@ void CompactLocationBarView::SetFocusAndSelection() {
void CompactLocationBarView::Update(const TabContents* contents) {
location_entry_->Update(contents);
- browser_actions_->RefreshBrowserActionViews();
}
@@ -78,8 +77,6 @@ void CompactLocationBarView::Init() {
// Reload button.
reload_ = new views::ImageButton(this);
- reload_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
- views::ImageButton::ALIGN_MIDDLE);
reload_->set_tag(IDC_RELOAD);
reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD));
reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD));
@@ -111,11 +108,15 @@ void CompactLocationBarView::Init() {
location_entry_view_->set_focus_view(this);
location_entry_view_->Attach(location_entry_->widget());
- // TODO(oshima): Add Star Button
- location_entry_->Update(browser()->GetSelectedTabContents());
+ star_ = new ToolbarStarToggle(this);
+ star_->SetDragController(this);
+ star_->set_profile(browser()->profile());
+ star_->set_host_view(this);
+ star_->set_bubble_positioner(this);
+ star_->Init();
+ AddChildView(star_);
- browser_actions_ = new BrowserActionsContainer(browser(), this);
- AddChildView(browser_actions_);
+ location_entry_->Update(browser()->GetSelectedTabContents());
}
////////////////////////////////////////////////////////////////////////////////
@@ -126,46 +127,39 @@ gfx::Size CompactLocationBarView::GetPreferredSize() {
return gfx::Size(); // Not initialized yet, do nothing.
gfx::Size reload_size = reload_->GetPreferredSize();
- gfx::Size ba_size = browser_actions_->GetPreferredSize();
- int width =
- reload_size.width() +
- std::max(kDefaultLocationEntryWidth,
- location_entry_view_->GetPreferredSize().width()) +
- ba_size.width();
- return gfx::Size(width, kDefaultLocationBarHeight);
+ gfx::Size star_size = star_->GetPreferredSize();
+ gfx::Size location_size = location_entry_view_->GetPreferredSize();
+
+ int max_height = std::max(reload_size.height(),
+ std::max(star_size.height(),
+ location_size.height()));
+ return gfx::Size(500, max_height);
}
void CompactLocationBarView::Layout() {
if (!reload_)
return; // Not initialized yet, do nothing.
- int cur_x = kCompactLocationLeftRightMargin;
-
- gfx::Size sz = reload_->GetPreferredSize();
- reload_->SetBounds(cur_x, 0, sz.width(), height());
- cur_x += sz.width() + kEntryLeftMargin;
-
- gfx::Size ba_size = browser_actions_->GetPreferredSize();
- browser_actions_->SetBounds(
- width() - ba_size.width(), 0, ba_size.width(), height());
- int location_entry_width = browser_actions_->x() - cur_x;
- if (ba_size.IsEmpty()) {
- // BrowserActionsContainer has its own margin on right.
- // Use the our margin when if the browser action is empty.
- location_entry_width -= kCompactLocationLeftRightMargin;
- }
-
- // The location bar gets the rest of the space in the middle.
- location_entry_view_->SetBounds(cur_x, 0, location_entry_width, height());
+ int cur_x = 0;
+ gfx::Size reload_size = reload_->GetPreferredSize();
+ int reload_height = std::min(reload_size.height(), height());
+ reload_->SetBounds(cur_x, (height() - reload_height) / 2,
+ reload_size.width(), reload_height);
+ cur_x += reload_size.width() + kWidgetsSeparatorWidth;
+
+ gfx::Size star_size = star_->GetPreferredSize();
+ int star_height = std::min(star_size.height(), height());
+ star_->SetBounds(cur_x, (height() - star_height) / 2,
+ star_size.width(), star_height);
+ cur_x += star_size.width();
+
+ // The location bar is located exactly to the right of the star button and
+ // takes all the space to the right except for small margin at the end.
+ int location_width = width() - cur_x - kWidgetsSeparatorWidth;
+ location_entry_view_->SetBounds(cur_x, 0, location_width, height());
}
void CompactLocationBarView::Paint(gfx::Canvas* canvas) {
- gfx::Rect lb = GetLocalBounds(true);
- ThemeProvider* tp = GetThemeProvider();
- gfx::Rect bounds;
- host()->GetThemePosition(&bounds);
- canvas->TileImageInt(*tp->GetBitmapNamed(IDR_THEME_TOOLBAR),
- bounds.x(), bounds.y(), 0, 0, lb.width(), lb.height());
View::Paint(canvas);
}
@@ -205,6 +199,7 @@ void CompactLocationBarView::OnChanged() {
}
void CompactLocationBarView::OnKillFocus() {
+ clb_host()->Hide(true);
}
void CompactLocationBarView::OnSetFocus() {
@@ -227,8 +222,59 @@ gfx::Rect CompactLocationBarView::GetLocationStackBounds() const {
gfx::Point lower_left(0, height());
ConvertPointToScreen(this, &lower_left);
gfx::Rect popup = gfx::Rect(lower_left.x(), lower_left.y(),
- kAutocompletePopupWidth, 0);
+ kCompactLocationBarDefaultWidth, 0);
return popup.AdjustToFit(GetWidget()->GetWindow()->GetBounds());
}
+////////////////////////////////////////////////////////////////////////////////
+// views::DragController overrides:
+void CompactLocationBarView::WriteDragData(views::View* sender,
+ int press_x,
+ int press_y,
+ OSExchangeData* data) {
+ DCHECK(
+ GetDragOperations(sender, press_x, press_y) != DragDropTypes::DRAG_NONE);
+
+ UserMetrics::RecordAction("CompactLocationBar_DragStar",
+ browser()->profile());
+
+ // If there is a bookmark for the URL, add the bookmark drag data for it. We
+ // do this to ensure the bookmark is moved, rather than creating an new
+ // bookmark.
+ TabContents* tab = browser()->GetSelectedTabContents();
+ if (tab) {
+ Profile* profile = browser()->profile();
+ if (profile && profile->GetBookmarkModel()) {
+ const BookmarkNode* node = profile->GetBookmarkModel()->
+ GetMostRecentlyAddedNodeForURL(tab->GetURL());
+ if (node) {
+ BookmarkDragData bookmark_data(node);
+ bookmark_data.Write(profile, data);
+ }
+ }
+
+ drag_utils::SetURLAndDragImage(tab->GetURL(),
+ UTF16ToWideHack(tab->GetTitle()),
+ tab->GetFavIcon(),
+ data);
+ }
+}
+
+int CompactLocationBarView::GetDragOperations(views::View* sender,
+ int x,
+ int y) {
+ DCHECK(sender == star_);
+ TabContents* tab = browser()->GetSelectedTabContents();
+ if (!tab || !tab->ShouldDisplayURL() || !tab->GetURL().is_valid()) {
+ return DragDropTypes::DRAG_NONE;
+ }
+ Profile* profile = browser()->profile();
+ if (profile && profile->GetBookmarkModel() &&
+ profile->GetBookmarkModel()->IsBookmarked(tab->GetURL())) {
+ return DragDropTypes::DRAG_MOVE | DragDropTypes::DRAG_COPY |
+ DragDropTypes::DRAG_LINK;
+ }
+ return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK;
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/compact_location_bar_view.h b/chrome/browser/chromeos/compact_location_bar_view.h
index 883a17f..16492a8 100644
--- a/chrome/browser/chromeos/compact_location_bar_view.h
+++ b/chrome/browser/chromeos/compact_location_bar_view.h
@@ -21,6 +21,7 @@ class ToolbarStarToggleGtk;
class Tab;
class TabContents;
class TabStrip;
+class ToolbarStarToggle;
namespace views {
class ImageButton;
@@ -35,7 +36,8 @@ namespace chromeos {
class CompactLocationBarView : public DropdownBarView,
public views::ButtonListener,
public AutocompleteEditController,
- public BubblePositioner {
+ public BubblePositioner,
+ public views::DragController {
public:
explicit CompactLocationBarView(CompactLocationBarHost* host);
~CompactLocationBarView();
@@ -45,6 +47,8 @@ class CompactLocationBarView : public DropdownBarView,
void Update(const TabContents* contents);
+ ToolbarStarToggle* star_button() const { return star_; }
+
private:
Browser* browser() const;
@@ -78,6 +82,20 @@ class CompactLocationBarView : public DropdownBarView,
// BubblePositioner implementation.
virtual gfx::Rect GetLocationStackBounds() const;
+ // views::DragController implementation.
+ virtual void WriteDragData(View* sender,
+ int press_x,
+ int press_y,
+ OSExchangeData* data);
+ virtual int GetDragOperations(View* sender, int x, int y);
+ virtual bool CanStartDrag(View* sender,
+ int press_x,
+ int press_y,
+ int x,
+ int y) {
+ return true;
+ }
+
CompactLocationBarHost* clb_host() {
return static_cast<CompactLocationBarHost*>(host());
}
@@ -87,6 +105,8 @@ class CompactLocationBarView : public DropdownBarView,
views::NativeViewHost* location_entry_view_;
BrowserActionsContainer* browser_actions_;
+ ToolbarStarToggle* star_;
+
DISALLOW_COPY_AND_ASSIGN(CompactLocationBarView);
};
diff --git a/chrome/browser/views/star_toggle.cc b/chrome/browser/views/star_toggle.cc
deleted file mode 100644
index ebb67ac..0000000
--- a/chrome/browser/views/star_toggle.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) 2006-2008 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/star_toggle.h"
-
-#include "app/gfx/canvas.h"
-#include "app/resource_bundle.h"
-#include "base/keyboard_codes.h"
-#include "chrome/app/chrome_dll_resource.h"
-#include "grit/theme_resources.h"
-
-StarToggle::StarToggle(Delegate* delegate)
- : delegate_(delegate),
- state_(false),
- change_state_immediately_(false) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- state_off_ = rb.GetBitmapNamed(IDR_CONTENT_STAR_OFF);
- state_on_ = rb.GetBitmapNamed(IDR_CONTENT_STAR_ON);
- SetFocusable(true);
-}
-
-StarToggle::~StarToggle() {
-}
-
-void StarToggle::SetState(bool s) {
- if (s != state_) {
- state_ = s;
- SchedulePaint();
- }
-}
-
-bool StarToggle::GetState() const {
- return state_;
-}
-
-void StarToggle::Paint(gfx::Canvas* canvas) {
- PaintFocusBorder(canvas);
- canvas->DrawBitmapInt(state_ ? *state_on_ : *state_off_,
- (width() - state_off_->width()) / 2,
- (height() - state_off_->height()) / 2);
-}
-
-gfx::Size StarToggle::GetPreferredSize() {
- return gfx::Size(state_off_->width(), state_off_->height());
-}
-
-bool StarToggle::OnMouseDragged(const views::MouseEvent& e) {
- return e.IsLeftMouseButton();
-}
-
-bool StarToggle::OnMousePressed(const views::MouseEvent& e) {
- if (e.IsLeftMouseButton() && HitTest(e.location())) {
- RequestFocus();
- return true;
- }
- return false;
-}
-
-void StarToggle::OnMouseReleased(const views::MouseEvent& e,
- bool canceled) {
- if (e.IsLeftMouseButton() && HitTest(e.location()))
- SwitchState();
-}
-
-bool StarToggle::OnKeyPressed(const views::KeyEvent& e) {
- if ((e.GetKeyCode() == base::VKEY_SPACE) ||
- (e.GetKeyCode() == base::VKEY_RETURN)) {
- SwitchState();
- return true;
- }
- return false;
-}
-
-void StarToggle::SwitchState() {
- const bool new_state = !state_;
- if (change_state_immediately_)
- state_ = new_state;
- SchedulePaint();
- delegate_->StarStateChanged(new_state);
-}
diff --git a/chrome/browser/views/star_toggle.h b/chrome/browser/views/star_toggle.h
deleted file mode 100644
index 1cfc0de..0000000
--- a/chrome/browser/views/star_toggle.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) 2006-2008 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_STAR_TOGGLE_H_
-#define CHROME_BROWSER_VIEWS_STAR_TOGGLE_H_
-
-#include "views/view.h"
-#include "views/event.h"
-
-class SkBitmap;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// A view subclass to implement the star button. The star button notifies its
-// Delegate when the state changes.
-//
-////////////////////////////////////////////////////////////////////////////////
-class StarToggle : public views::View {
- public:
- class Delegate {
- public:
- // Called when the star is toggled.
- virtual void StarStateChanged(bool state) = 0;
- };
-
- explicit StarToggle(Delegate* delegate);
- virtual ~StarToggle();
-
- // Set whether the star is checked.
- void SetState(bool s);
- bool GetState() const;
-
- // If true (the default) the state is immediately changed on a mouse release.
- // If false, on mouse release the delegate is notified, but the state is not
- // changed.
- void set_change_state_immediately(bool value) {
- change_state_immediately_ = value;
- }
-
- // Check/uncheck the star.
- void SwitchState();
-
- // Overriden from view.
- void Paint(gfx::Canvas* canvas);
- gfx::Size GetPreferredSize();
- virtual bool OnMousePressed(const views::MouseEvent& e);
- virtual bool OnMouseDragged(const views::MouseEvent& event);
- virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled);
- bool OnKeyPressed(const views::KeyEvent& e);
-
- private:
- // The state.
- bool state_;
-
- // Our bitmap.
- SkBitmap* state_off_;
- SkBitmap* state_on_;
-
- // Parent to be notified.
- Delegate* delegate_;
-
- // See note in setter.
- bool change_state_immediately_;
-
- DISALLOW_EVIL_CONSTRUCTORS(StarToggle);
-};
-
-#endif // CHROME_BROWSER_VIEWS_STAR_TOGGLE_H_
diff --git a/chrome/browser/views/toolbar_star_toggle.cc b/chrome/browser/views/toolbar_star_toggle.cc
index 9cd2e7b..6b93067 100644
--- a/chrome/browser/views/toolbar_star_toggle.cc
+++ b/chrome/browser/views/toolbar_star_toggle.cc
@@ -4,12 +4,18 @@
#include "chrome/browser/views/toolbar_star_toggle.h"
+#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_theme_provider.h"
+#include "chrome/browser/bubble_positioner.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/views/browser_dialogs.h"
-#include "chrome/browser/views/toolbar_view.h"
+#include "chrome/browser/view_ids.h"
#include "googleurl/src/gurl.h"
+#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
using base::TimeTicks;
@@ -27,15 +33,42 @@ using base::TimeTicks;
// with the bubble because it has other native windows.
static const int64 kDisallowClickMS = 40;
-ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener,
- ToolbarView* host)
- : ToggleImageButton(listener),
- host_(host),
+ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* button_listener)
+ : ToggleImageButton(button_listener),
+ profile_(NULL),
+ host_view_(NULL),
+ bubble_positioner_(NULL),
ignore_click_(false) {
}
+void ToolbarStarToggle::Init() {
+ ThemeProvider* tp = profile_->GetThemeProvider();
+
+ set_tag(IDC_BOOKMARK_PAGE);
+ SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_STAR));
+ SetToggledTooltipText(l10n_util::GetString(IDS_TOOLTIP_STARRED));
+ SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR));
+ SetID(VIEW_ID_STAR_BUTTON);
+
+ // Load images.
+ SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND);
+ SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND);
+
+ SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_STAR));
+ SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_STAR_H));
+ SetImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_STAR_P));
+ SetImage(views::CustomButton::BS_DISABLED, tp->GetBitmapNamed(IDR_STAR_D));
+ SetToggledImage(views::CustomButton::BS_NORMAL,
+ tp->GetBitmapNamed(IDR_STARRED));
+ SetToggledImage(views::CustomButton::BS_HOT,
+ tp->GetBitmapNamed(IDR_STARRED_H));
+ SetToggledImage(views::CustomButton::BS_PUSHED,
+ tp->GetBitmapNamed(IDR_STARRED_P));
+ SetBackground(color, background, tp->GetBitmapNamed(IDR_STAR_MASK));
+}
+
void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
- gfx::Rect bounds(host_->GetLocationStackBounds());
+ gfx::Rect bounds(bubble_positioner_->GetLocationStackBounds());
gfx::Point star_location;
views::View::ConvertPointToScreen(this, &star_location);
// The visual center of the star is not centered within the bounds. The star
@@ -49,12 +82,12 @@ void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
// order to place the star's central pixel on the right side of the bounds'
// center-line, so that the arrow's center will line up.
//
- // TODO: If the InfoBubble used mirroring transformations maybe this could
- // become symmetric (-1 : 1).
+ // TODO(pkasting): If the InfoBubble used mirroring transformations maybe this
+ // could become symmetric (-1 : 1).
bounds.set_x(star_location.x() + (UILayoutIsRightToLeft() ? -2 : 1));
bounds.set_width(width());
- browser::ShowBookmarkBubbleView(host_->GetWindow(), bounds, this,
- host_->profile(), url, newly_bookmarked);
+ browser::ShowBookmarkBubbleView(host_view_->GetWindow(), bounds, this,
+ profile_, url, newly_bookmarked);
}
bool ToolbarStarToggle::OnMousePressed(const views::MouseEvent& e) {
diff --git a/chrome/browser/views/toolbar_star_toggle.h b/chrome/browser/views/toolbar_star_toggle.h
index 547fc19..68d8140 100644
--- a/chrome/browser/views/toolbar_star_toggle.h
+++ b/chrome/browser/views/toolbar_star_toggle.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -9,17 +9,30 @@
#include "chrome/browser/views/info_bubble.h"
#include "views/controls/button/image_button.h"
+class BubblePositioner;
class GURL;
-class ToolbarView;
+class Profile;
+
+namespace views {
+class ButtonListener;
+class View;
+} // namespace views
// ToolbarStarToggle is used for the star button on the toolbar, allowing the
// user to star the current page. ToolbarStarToggle manages showing the
// InfoBubble and rendering the appropriate state while the bubble is visible.
-
class ToolbarStarToggle : public views::ToggleImageButton,
public InfoBubbleDelegate {
public:
- ToolbarStarToggle(views::ButtonListener* listener, ToolbarView* host);
+ explicit ToolbarStarToggle(views::ButtonListener* button_listener);
+
+ void set_profile(Profile* profile) { profile_ = profile; }
+ void set_host_view(views::View* host_view) { host_view_ = host_view; }
+ void set_bubble_positioner(BubblePositioner* bubble_positioner) {
+ bubble_positioner_ = bubble_positioner;
+ }
+
+ void Init();
// If the bubble isn't showing, shows it.
void ShowStarBubble(const GURL& url, bool newly_bookmarked);
@@ -45,8 +58,14 @@ class ToolbarStarToggle : public views::ToggleImageButton,
bool closed_by_escape);
virtual bool CloseOnEscape();
- // Contains us.
- ToolbarView* host_;
+ // Profile with bookmarks info.
+ Profile* profile_;
+
+ // View that hosts us.
+ views::View* host_view_;
+
+// Positioner for bookmark bubble.
+ BubblePositioner* bubble_positioner_;
// Time the bubble last closed.
base::TimeTicks bubble_closed_time_;
@@ -55,7 +74,7 @@ class ToolbarStarToggle : public views::ToggleImageButton,
// the amount of time between when the bubble clicked and now.
bool ignore_click_;
- DISALLOW_EVIL_CONSTRUCTORS(ToolbarStarToggle);
+ DISALLOW_COPY_AND_ASSIGN(ToolbarStarToggle);
};
#endif // CHROME_BROWSER_VIEWS_TOOLBAR_STAR_TOGGLE_H_
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index d3f76aba..0762ce2 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/views/toolbar_view.h"
+#include <algorithm>
#include <string>
#include "app/drag_drop_types.h"
@@ -565,13 +566,12 @@ void ToolbarView::CreateLeftSideControls() {
}
void ToolbarView::CreateCenterStack(Profile *profile) {
- star_ = new ToolbarStarToggle(this, this);
- star_->set_tag(IDC_BOOKMARK_PAGE);
+ star_ = new ToolbarStarToggle(this);
star_->SetDragController(this);
- star_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_STAR));
- star_->SetToggledTooltipText(l10n_util::GetString(IDS_TOOLTIP_STARRED));
- star_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR));
- star_->SetID(VIEW_ID_STAR_BUTTON);
+ star_->set_profile(profile);
+ star_->set_host_view(this);
+ star_->set_bubble_positioner(this);
+ star_->Init();
AddChildView(star_);
location_bar_ = new LocationBarView(profile, browser_->command_updater(),
@@ -669,21 +669,6 @@ void ToolbarView::LoadCenterStackImages() {
SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND);
SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND);
- star_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_STAR));
- star_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_STAR_H));
- star_->SetImage(views::CustomButton::BS_PUSHED,
- tp->GetBitmapNamed(IDR_STAR_P));
- star_->SetImage(views::CustomButton::BS_DISABLED,
- tp->GetBitmapNamed(IDR_STAR_D));
- star_->SetToggledImage(views::CustomButton::BS_NORMAL,
- tp->GetBitmapNamed(IDR_STARRED));
- star_->SetToggledImage(views::CustomButton::BS_HOT,
- tp->GetBitmapNamed(IDR_STARRED_H));
- star_->SetToggledImage(views::CustomButton::BS_PUSHED,
- tp->GetBitmapNamed(IDR_STARRED_P));
- star_->SetBackground(color, background,
- tp->GetBitmapNamed(IDR_STAR_MASK));
-
go_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_GO));
go_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_GO_H));
go_->SetImage(views::CustomButton::BS_PUSHED, tp->GetBitmapNamed(IDR_GO_P));