summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 02:38:19 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 02:38:19 +0000
commitc100bb1bf56c6cc9ed2c03573432c578d8b4acaa (patch)
tree75f64307149af8f7e15bb66ad7dd1f3c19b3ca30
parentd5a30959562915bfefe907265ca17174c7aedfc6 (diff)
downloadchromium_src-c100bb1bf56c6cc9ed2c03573432c578d8b4acaa.zip
chromium_src-c100bb1bf56c6cc9ed2c03573432c578d8b4acaa.tar.gz
chromium_src-c100bb1bf56c6cc9ed2c03573432c578d8b4acaa.tar.bz2
Revert 38166 - Added Star button to compact navigation mode.
BUG=32326 TEST=Switch Chrome to compact mode by pressing CtrlShiftC. Test that Star icon works. Review URL: http://codereview.chromium.org/543215 TBR=avayvod@chromium.org Review URL: http://codereview.chromium.org/561081 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38171 0039d316-1c4b-4281-b951-d872f2087c98
-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, 240 insertions, 220 deletions
diff --git a/chrome/browser/chromeos/browser_view.cc b/chrome/browser/chromeos/browser_view.cc
index cffeb67..b9c8bbd 100644
--- a/chrome/browser/chromeos/browser_view.cc
+++ b/chrome/browser/chromeos/browser_view.cc
@@ -27,7 +27,6 @@
#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"
@@ -430,19 +429,6 @@ 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 a8d0470..278e134 100644
--- a/chrome/browser/chromeos/browser_view.h
+++ b/chrome/browser/chromeos/browser_view.h
@@ -63,8 +63,6 @@ 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 98d4325..56a2fc4 100644
--- a/chrome/browser/chromeos/compact_location_bar_host.cc
+++ b/chrome/browser/chromeos/compact_location_bar_host.cc
@@ -4,8 +4,6 @@
#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"
@@ -21,7 +19,6 @@
#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"
@@ -262,10 +259,6 @@ 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 da1bb9c..d386ac5 100644
--- a/chrome/browser/chromeos/compact_location_bar_host.h
+++ b/chrome/browser/chromeos/compact_location_bar_host.h
@@ -16,7 +16,6 @@
class BrowserView;
class TabContents;
class Tab;
-class ToolbarStarToggle;
namespace chromeos {
@@ -61,9 +60,6 @@ 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 ce9606b..16b00c4 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/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"
namespace chromeos {
-
-const int kCompactLocationBarDefaultWidth = 700;
-const int kWidgetsSeparatorWidth = 2;
+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;
CompactLocationBarView::CompactLocationBarView(CompactLocationBarHost* host)
: DropdownBarView(host),
reload_(NULL),
- star_(NULL) {
- set_background(views::Background::CreateStandardPanelBackground());
+ location_entry_view_(NULL),
+ browser_actions_(NULL) {
SetFocusable(true);
}
@@ -60,6 +60,7 @@ void CompactLocationBarView::SetFocusAndSelection() {
void CompactLocationBarView::Update(const TabContents* contents) {
location_entry_->Update(contents);
+ browser_actions_->RefreshBrowserActionViews();
}
@@ -77,6 +78,8 @@ 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));
@@ -108,15 +111,11 @@ void CompactLocationBarView::Init() {
location_entry_view_->set_focus_view(this);
location_entry_view_->Attach(location_entry_->widget());
- 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_);
-
+ // TODO(oshima): Add Star Button
location_entry_->Update(browser()->GetSelectedTabContents());
+
+ browser_actions_ = new BrowserActionsContainer(browser(), this);
+ AddChildView(browser_actions_);
}
////////////////////////////////////////////////////////////////////////////////
@@ -127,39 +126,46 @@ 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();
-
- int max_height = std::max(reload_size.height(),
- std::max(star_size.height(),
- location_size.height()));
- return gfx::Size(500, max_height);
+ 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);
}
void CompactLocationBarView::Layout() {
if (!reload_)
return; // Not initialized yet, do nothing.
- 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());
+ 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());
}
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);
}
@@ -199,7 +205,6 @@ void CompactLocationBarView::OnChanged() {
}
void CompactLocationBarView::OnKillFocus() {
- clb_host()->Hide(true);
}
void CompactLocationBarView::OnSetFocus() {
@@ -222,59 +227,8 @@ 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(),
- kCompactLocationBarDefaultWidth, 0);
+ kAutocompletePopupWidth, 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 16492a8..883a17f 100644
--- a/chrome/browser/chromeos/compact_location_bar_view.h
+++ b/chrome/browser/chromeos/compact_location_bar_view.h
@@ -21,7 +21,6 @@ class ToolbarStarToggleGtk;
class Tab;
class TabContents;
class TabStrip;
-class ToolbarStarToggle;
namespace views {
class ImageButton;
@@ -36,8 +35,7 @@ namespace chromeos {
class CompactLocationBarView : public DropdownBarView,
public views::ButtonListener,
public AutocompleteEditController,
- public BubblePositioner,
- public views::DragController {
+ public BubblePositioner {
public:
explicit CompactLocationBarView(CompactLocationBarHost* host);
~CompactLocationBarView();
@@ -47,8 +45,6 @@ class CompactLocationBarView : public DropdownBarView,
void Update(const TabContents* contents);
- ToolbarStarToggle* star_button() const { return star_; }
-
private:
Browser* browser() const;
@@ -82,20 +78,6 @@ 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());
}
@@ -105,8 +87,6 @@ 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
new file mode 100644
index 0000000..ebb67ac
--- /dev/null
+++ b/chrome/browser/views/star_toggle.cc
@@ -0,0 +1,81 @@
+// 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
new file mode 100644
index 0000000..1cfc0de
--- /dev/null
+++ b/chrome/browser/views/star_toggle.h
@@ -0,0 +1,69 @@
+// 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 6b93067..9cd2e7b 100644
--- a/chrome/browser/views/toolbar_star_toggle.cc
+++ b/chrome/browser/views/toolbar_star_toggle.cc
@@ -4,18 +4,12 @@
#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/view_ids.h"
+#include "chrome/browser/views/toolbar_view.h"
#include "googleurl/src/gurl.h"
-#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
using base::TimeTicks;
@@ -33,42 +27,15 @@ using base::TimeTicks;
// with the bubble because it has other native windows.
static const int64 kDisallowClickMS = 40;
-ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* button_listener)
- : ToggleImageButton(button_listener),
- profile_(NULL),
- host_view_(NULL),
- bubble_positioner_(NULL),
+ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener,
+ ToolbarView* host)
+ : ToggleImageButton(listener),
+ host_(host),
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(bubble_positioner_->GetLocationStackBounds());
+ gfx::Rect bounds(host_->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
@@ -82,12 +49,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(pkasting): If the InfoBubble used mirroring transformations maybe this
- // could become symmetric (-1 : 1).
+ // TODO: 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_view_->GetWindow(), bounds, this,
- profile_, url, newly_bookmarked);
+ browser::ShowBookmarkBubbleView(host_->GetWindow(), bounds, this,
+ host_->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 68d8140..547fc19 100644
--- a/chrome/browser/views/toolbar_star_toggle.h
+++ b/chrome/browser/views/toolbar_star_toggle.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -9,30 +9,17 @@
#include "chrome/browser/views/info_bubble.h"
#include "views/controls/button/image_button.h"
-class BubblePositioner;
class GURL;
-class Profile;
-
-namespace views {
-class ButtonListener;
-class View;
-} // namespace views
+class ToolbarView;
// 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:
- 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();
+ ToolbarStarToggle(views::ButtonListener* listener, ToolbarView* host);
// If the bubble isn't showing, shows it.
void ShowStarBubble(const GURL& url, bool newly_bookmarked);
@@ -58,14 +45,8 @@ class ToolbarStarToggle : public views::ToggleImageButton,
bool closed_by_escape);
virtual bool CloseOnEscape();
- // Profile with bookmarks info.
- Profile* profile_;
-
- // View that hosts us.
- views::View* host_view_;
-
-// Positioner for bookmark bubble.
- BubblePositioner* bubble_positioner_;
+ // Contains us.
+ ToolbarView* host_;
// Time the bubble last closed.
base::TimeTicks bubble_closed_time_;
@@ -74,7 +55,7 @@ class ToolbarStarToggle : public views::ToggleImageButton,
// the amount of time between when the bubble clicked and now.
bool ignore_click_;
- DISALLOW_COPY_AND_ASSIGN(ToolbarStarToggle);
+ DISALLOW_EVIL_CONSTRUCTORS(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 0762ce2..d3f76aba 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/views/toolbar_view.h"
-#include <algorithm>
#include <string>
#include "app/drag_drop_types.h"
@@ -566,12 +565,13 @@ void ToolbarView::CreateLeftSideControls() {
}
void ToolbarView::CreateCenterStack(Profile *profile) {
- star_ = new ToolbarStarToggle(this);
+ star_ = new ToolbarStarToggle(this, this);
+ star_->set_tag(IDC_BOOKMARK_PAGE);
star_->SetDragController(this);
- star_->set_profile(profile);
- star_->set_host_view(this);
- star_->set_bubble_positioner(this);
- star_->Init();
+ 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);
AddChildView(star_);
location_bar_ = new LocationBarView(profile, browser_->command_updater(),
@@ -669,6 +669,21 @@ 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));