Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4291)

Unified Diff: chrome/browser/ui/views/location_bar/star_view.cc

Issue 25373009: Translate: New Bubble UX (for the view toolkit) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sky's review (3) Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/location_bar/star_view.cc
diff --git a/chrome/browser/ui/views/location_bar/star_view.cc b/chrome/browser/ui/views/location_bar/star_view.cc
index 7a3c955843de0f4843997619d41bc0302e3d1257..c7e402f3661de21106a3a06e9604fd22bf09a288 100644
--- a/chrome/browser/ui/views/location_bar/star_view.cc
+++ b/chrome/browser/ui/views/location_bar/star_view.cc
@@ -8,93 +8,63 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_stats.h"
-#include "chrome/browser/command_updater.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
-#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
+#include "chrome/browser/ui/views/location_bar/bubble_icon_view_delegate.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
-#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
-#include "ui/events/event.h"
-StarView::StarView(CommandUpdater* command_updater)
- : command_updater_(command_updater),
- suppress_mouse_released_action_(false) {
- set_id(VIEW_ID_STAR_BUTTON);
- SetToggled(false);
- set_accessibility_focusable(true);
- LocationBarView::InitTouchableLocationBarChildView(this);
-}
-
-StarView::~StarView() {}
-
-void StarView::SetToggled(bool on) {
- SetTooltipText(l10n_util::GetStringUTF16(
- on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR));
- SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- on ? IDR_STAR_LIT : IDR_STAR));
-}
-
-void StarView::GetAccessibleState(ui::AccessibleViewState* state) {
- ImageView::GetAccessibleState(state);
- state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
-}
+namespace {
-bool StarView::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
- // Don't show tooltip to distract user if BookmarkBubbleView is showing.
- if (BookmarkBubbleView::IsShowing())
- return false;
-
- return views::ImageView::GetTooltipText(p, tooltip);
-}
-
-bool StarView::OnMousePressed(const ui::MouseEvent& event) {
- // If the bookmark bubble is showing then don't reshow it when the mouse is
- // released.
- suppress_mouse_released_action_ = BookmarkBubbleView::IsShowing();
-
- // We want to show the bubble on mouse release; that is the standard behavior
- // for buttons.
- return true;
-}
+class BubbleIconViewDelegateImpl : public BubbleIconViewDelegate {
+ public:
+ BubbleIconViewDelegateImpl() {
+ }
-void StarView::OnMouseReleased(const ui::MouseEvent& event) {
- // If this is the second click on this view then the bookmark bubble was
- // showing on the mouse pressed event and is hidden now. Prevent the bubble
- // from reshowing by doing nothing here.
- if (suppress_mouse_released_action_) {
- suppress_mouse_released_action_ = false;
- return;
+ virtual bool IsBubbleShowing() const OVERRIDE {
+ return BookmarkBubbleView::IsShowing();
}
- if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
+ virtual void OnExecutingByMouse() OVERRIDE {
UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
BOOKMARK_ENTRY_POINT_STAR_MOUSE,
BOOKMARK_ENTRY_POINT_LIMIT);
- command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE_FROM_STAR);
}
-}
-bool StarView::OnKeyPressed(const ui::KeyEvent& event) {
- if (event.key_code() == ui::VKEY_SPACE ||
- event.key_code() == ui::VKEY_RETURN) {
+ virtual void OnExecutingByKey() OVERRIDE {
UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
BOOKMARK_ENTRY_POINT_STAR_KEY,
BOOKMARK_ENTRY_POINT_LIMIT);
- command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE_FROM_STAR);
- return true;
}
- return false;
-}
-void StarView::OnGestureEvent(ui::GestureEvent* event) {
- if (event->type() == ui::ET_GESTURE_TAP) {
+ virtual void OnExecutingByGesture() OVERRIDE {
UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
BOOKMARK_ENTRY_POINT_STAR_GESTURE,
BOOKMARK_ENTRY_POINT_LIMIT);
- command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE_FROM_STAR);
- event->SetHandled();
}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BubbleIconViewDelegateImpl);
+};
+
+} // namespace
+
+StarView::StarView(CommandUpdater* command_updater)
+ : BubbleIconView(command_updater, IDC_BOOKMARK_PAGE_FROM_STAR) {
+ delegate_.reset(new BubbleIconViewDelegateImpl);
+ set_delegate(delegate_.get());
+
+ set_id(VIEW_ID_STAR_BUTTON);
+ SetToggled(false);
+}
+
+StarView::~StarView() {}
+
+void StarView::SetToggled(bool on) {
+ SetTooltipText(l10n_util::GetStringUTF16(
+ on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR));
+ SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ on ? IDR_STAR_LIT : IDR_STAR));
}

Powered by Google App Engine
This is Rietveld 408576698