summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 23:06:34 +0000
committeravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 23:06:34 +0000
commitc2d602b32d86c44e6eb1fe6b1d12fda314e21a62 (patch)
tree899d04cc3db6a9143d6073cf0774912ae645ea33 /chrome
parentcce95d69e3957b1e5d9762febd4889ff94f7e7fd (diff)
downloadchromium_src-c2d602b32d86c44e6eb1fe6b1d12fda314e21a62.zip
chromium_src-c2d602b32d86c44e6eb1fe6b1d12fda314e21a62.tar.gz
chromium_src-c2d602b32d86c44e6eb1fe6b1d12fda314e21a62.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/577026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-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.h6
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.cc86
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.h21
-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.cc51
-rw-r--r--chrome/browser/views/toolbar_star_toggle.h33
-rw-r--r--chrome/browser/views/toolbar_view.cc27
-rwxr-xr-xchrome/chrome_browser.gypi2
12 files changed, 202 insertions, 197 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..6fbc99b 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,7 +61,10 @@ class CompactLocationBarHost : public DropdownBarHost,
// Enable/disable the compact location bar.
void SetEnabled(bool enabled);
- // Overridehden from DropdownBarhost.
+ // Returns the star button for compact location bar.
+ ToolbarStarToggle* GetStarButton();
+
+ // Overridden 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..cfbcfb8 100644
--- a/chrome/browser/chromeos/compact_location_bar_view.cc
+++ b/chrome/browser/chromeos/compact_location_bar_view.cc
@@ -8,25 +8,32 @@
#include <algorithm>
#include "app/l10n_util.h"
+#include "app/drag_drop_types.h"
#include "app/gfx/canvas.h"
#include "app/resource_bundle.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"
@@ -38,12 +45,13 @@ 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 kWidgetsSeparatorWidth = 2;
CompactLocationBarView::CompactLocationBarView(CompactLocationBarHost* host)
: DropdownBarView(host),
reload_(NULL),
- location_entry_view_(NULL),
- browser_actions_(NULL) {
+ browser_actions_(NULL),
+ star_(NULL) {
SetFocusable(true);
}
@@ -111,7 +119,14 @@ void CompactLocationBarView::Init() {
location_entry_view_->set_focus_view(this);
location_entry_view_->Attach(location_entry_->widget());
- // TODO(oshima): Add Star Button
+ 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_);
+
location_entry_->Update(browser()->GetSelectedTabContents());
browser_actions_ = new BrowserActionsContainer(browser(), this);
@@ -126,9 +141,11 @@ gfx::Size CompactLocationBarView::GetPreferredSize() {
return gfx::Size(); // Not initialized yet, do nothing.
gfx::Size reload_size = reload_->GetPreferredSize();
+ gfx::Size star_size = star_->GetPreferredSize();
+ gfx::Size location_size = location_entry_view_->GetPreferredSize();
gfx::Size ba_size = browser_actions_->GetPreferredSize();
int width =
- reload_size.width() +
+ reload_size.width() + kEntryLeftMargin + star_size.width() +
std::max(kDefaultLocationEntryWidth,
location_entry_view_->GetPreferredSize().width()) +
ba_size.width();
@@ -141,9 +158,13 @@ void CompactLocationBarView::Layout() {
int cur_x = kCompactLocationLeftRightMargin;
- gfx::Size sz = reload_->GetPreferredSize();
- reload_->SetBounds(cur_x, 0, sz.width(), height());
- cur_x += sz.width() + kEntryLeftMargin;
+ gfx::Size reload_size = reload_->GetPreferredSize();
+ reload_->SetBounds(cur_x, 0, reload_size.width(), height());
+ cur_x += reload_size.width() + kEntryLeftMargin;
+
+ gfx::Size star_size = star_->GetPreferredSize();
+ star_->SetBounds(cur_x, 0, star_size.width(), star_size.height());
+ cur_x += star_size.width();
gfx::Size ba_size = browser_actions_->GetPreferredSize();
browser_actions_->SetBounds(
@@ -231,4 +252,55 @@ gfx::Rect CompactLocationBarView::GetLocationStackBounds() const {
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..d6ca228 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());
}
@@ -86,6 +104,7 @@ class CompactLocationBarView : public DropdownBarView,
scoped_ptr<AutocompleteEditViewGtk> location_entry_;
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..0c00475 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)
+ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener)
: ToggleImageButton(listener),
- host_(host),
+ 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..9cc1c7d 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,8 +9,14 @@
#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
@@ -19,7 +25,16 @@ class ToolbarView;
class ToolbarStarToggle : public views::ToggleImageButton,
public InfoBubbleDelegate {
public:
- ToolbarStarToggle(views::ButtonListener* listener, ToolbarView* host);
+ explicit ToolbarStarToggle(views::ButtonListener* 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;
+ }
+
+ // Sets up all labels and images for the button.
+ void Init();
// If the bubble isn't showing, shows it.
void ShowStarBubble(const GURL& url, bool newly_bookmarked);
@@ -45,8 +60,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 +76,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));
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 859d8b2..b0023e9 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1951,8 +1951,6 @@
'browser/views/select_profile_dialog.cc',
'browser/views/select_profile_dialog.h',
'browser/views/shell_dialogs_win.cc',
- 'browser/views/star_toggle.cc',
- 'browser/views/star_toggle.h',
'browser/views/status_bubble_views.cc',
'browser/views/status_bubble_views.h',
'browser/views/tab_icon_view.cc',