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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

Issue 1757993004: Added ink drop hover/ripple to menu hosting bookmark buttons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated the ripple to behave resonably when showing context menus. Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 #include "ui/gfx/canvas.h" 87 #include "ui/gfx/canvas.h"
88 #include "ui/gfx/color_utils.h" 88 #include "ui/gfx/color_utils.h"
89 #include "ui/gfx/favicon_size.h" 89 #include "ui/gfx/favicon_size.h"
90 #include "ui/gfx/paint_vector_icon.h" 90 #include "ui/gfx/paint_vector_icon.h"
91 #include "ui/gfx/scoped_canvas.h" 91 #include "ui/gfx/scoped_canvas.h"
92 #include "ui/gfx/text_constants.h" 92 #include "ui/gfx/text_constants.h"
93 #include "ui/gfx/text_elider.h" 93 #include "ui/gfx/text_elider.h"
94 #include "ui/gfx/vector_icons_public.h" 94 #include "ui/gfx/vector_icons_public.h"
95 #include "ui/resources/grit/ui_resources.h" 95 #include "ui/resources/grit/ui_resources.h"
96 #include "ui/views/animation/button_ink_drop_delegate.h" 96 #include "ui/views/animation/button_ink_drop_delegate.h"
97 #include "ui/views/animation/flood_fill_ink_drop_animation.h"
98 #include "ui/views/animation/ink_drop_hover.h"
97 #include "ui/views/button_drag_utils.h" 99 #include "ui/views/button_drag_utils.h"
98 #include "ui/views/controls/button/label_button.h" 100 #include "ui/views/controls/button/label_button.h"
99 #include "ui/views/controls/button/label_button_border.h" 101 #include "ui/views/controls/button/label_button_border.h"
100 #include "ui/views/controls/button/menu_button.h" 102 #include "ui/views/controls/button/menu_button.h"
101 #include "ui/views/controls/label.h" 103 #include "ui/views/controls/label.h"
102 #include "ui/views/drag_utils.h" 104 #include "ui/views/drag_utils.h"
103 #include "ui/views/metrics.h" 105 #include "ui/views/metrics.h"
104 #include "ui/views/view_constants.h" 106 #include "ui/views/view_constants.h"
105 #include "ui/views/widget/tooltip_manager.h" 107 #include "ui/views/widget/tooltip_manager.h"
106 #include "ui/views/widget/widget.h" 108 #include "ui/views/widget/widget.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 gfx::ImageSkia* GetImageSkiaNamed(int id) { 183 gfx::ImageSkia* GetImageSkiaNamed(int id) {
182 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); 184 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id);
183 } 185 }
184 186
185 int GetHorizontalMargin() { 187 int GetHorizontalMargin() {
186 return kHorizontalMargin[ui::MaterialDesignController::GetMode()]; 188 return kHorizontalMargin[ui::MaterialDesignController::GetMode()];
187 } 189 }
188 190
189 // BookmarkButtonBase ----------------------------------------------- 191 // BookmarkButtonBase -----------------------------------------------
190 192
191 // Base class for buttons used on the bookmark bar. 193 // Base class for non-menu hosting buttons used on the bookmark bar.
192 194
193 class BookmarkButtonBase : public views::LabelButton { 195 class BookmarkButtonBase : public views::LabelButton {
194 public: 196 public:
195 BookmarkButtonBase(views::ButtonListener* listener, 197 BookmarkButtonBase(views::ButtonListener* listener,
196 const base::string16& title) 198 const base::string16& title)
197 : LabelButton(listener, title), ink_drop_delegate_(this, this) { 199 : LabelButton(listener, title), ink_drop_delegate_(this, this) {
198 SetElideBehavior(kElideBehavior); 200 SetElideBehavior(kElideBehavior);
199 set_ink_drop_delegate(&ink_drop_delegate_); 201 set_ink_drop_delegate(&ink_drop_delegate_);
200 set_has_ink_drop_action_on_click(true); 202 set_has_ink_drop_action_on_click(true);
201 show_animation_.reset(new gfx::SlideAnimation(this)); 203 show_animation_.reset(new gfx::SlideAnimation(this));
(...skipping 18 matching lines...) Expand all
220 kButtonPaddingHorizontal)); 222 kButtonPaddingHorizontal));
221 return border; 223 return border;
222 } 224 }
223 225
224 bool IsTriggerableEvent(const ui::Event& e) override { 226 bool IsTriggerableEvent(const ui::Event& e) override {
225 return e.type() == ui::ET_GESTURE_TAP || 227 return e.type() == ui::ET_GESTURE_TAP ||
226 e.type() == ui::ET_GESTURE_TAP_DOWN || 228 e.type() == ui::ET_GESTURE_TAP_DOWN ||
227 event_utils::IsPossibleDispositionEvent(e); 229 event_utils::IsPossibleDispositionEvent(e);
228 } 230 }
229 231
232 scoped_ptr<views::InkDropAnimation> CreateInkDropAnimation() const override {
233 return make_scoped_ptr(new views::FloodFillInkDropAnimation(
234 size(), GetInkDropCenter(), GetInkDropBaseColor()));
235 }
236
237 scoped_ptr<views::InkDropHover> CreateInkDropHover() const override {
238 if (!ShouldShowInkDropHover())
239 return nullptr;
240 return make_scoped_ptr(new views::InkDropHover(
241 size(), 0, GetInkDropCenter(), GetInkDropBaseColor()));
242 }
243
230 SkColor GetInkDropBaseColor() const override { 244 SkColor GetInkDropBaseColor() const override {
231 return GetThemeProvider()->GetColor( 245 return GetThemeProvider()
varkha 2016/03/11 17:57:17 When is there no ThemeProvider? Maybe a comment.
bruthig 2016/03/11 21:58:20 Done.
232 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); 246 ? GetThemeProvider()->GetColor(
247 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON)
248 : views::LabelButton::GetInkDropBaseColor();
233 } 249 }
234 250
235 private: 251 private:
236 scoped_ptr<gfx::SlideAnimation> show_animation_; 252 scoped_ptr<gfx::SlideAnimation> show_animation_;
237 253
238 // Controls the visual feedback for the button state. 254 // Controls the visual feedback for the button state.
239 views::ButtonInkDropDelegate ink_drop_delegate_; 255 views::ButtonInkDropDelegate ink_drop_delegate_;
240 256
241 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); 257 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase);
242 }; 258 };
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 309
294 const char* GetClassName() const override { return kViewClassName; } 310 const char* GetClassName() const override { return kViewClassName; }
295 311
296 private: 312 private:
297 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); 313 DISALLOW_COPY_AND_ASSIGN(ShortcutButton);
298 }; 314 };
299 315
300 // static 316 // static
301 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; 317 const char ShortcutButton::kViewClassName[] = "ShortcutButton";
302 318
303 // BookmarkFolderButton ------------------------------------------------------- 319 // BookmarkFolderButton -------------------------------------------------------
varkha 2016/03/11 17:57:17 Move this down and add another section.
bruthig 2016/03/11 21:58:20 Done.
304 320
321 // Base class for menu hosting buttons used on the bookmark bar.
322 class BookmarkMenuButtonBase : public views::MenuButton {
323 public:
324 BookmarkMenuButtonBase(const base::string16& title,
325 views::MenuButtonListener* menu_button_listener,
326 bool show_menu_marker)
327 : MenuButton(title, menu_button_listener, show_menu_marker),
328 ink_drop_delegate_(this, this) {
329 set_ink_drop_delegate(&ink_drop_delegate_);
330 }
331
332 scoped_ptr<views::InkDropAnimation> CreateInkDropAnimation() const override {
333 return make_scoped_ptr(new views::FloodFillInkDropAnimation(
334 size(), GetInkDropCenter(), GetInkDropBaseColor()));
335 }
336
337 scoped_ptr<views::InkDropHover> CreateInkDropHover() const override {
338 if (!ShouldShowInkDropHover())
339 return nullptr;
340 return make_scoped_ptr(new views::InkDropHover(
341 size(), 0, GetInkDropCenter(), GetInkDropBaseColor()));
342 }
343
344 SkColor GetInkDropBaseColor() const override {
345 return GetThemeProvider()
346 ? GetThemeProvider()->GetColor(
347 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON)
348 : views::LabelButton::GetInkDropBaseColor();
349 }
350
351 private:
352 // Controls the visual feedback for the button state.
353 views::ButtonInkDropDelegate ink_drop_delegate_;
354
355 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuButtonBase);
356 };
357
305 // Buttons used for folders on the bookmark bar, including the 'other folders' 358 // Buttons used for folders on the bookmark bar, including the 'other folders'
306 // button. 359 // button.
307 class BookmarkFolderButton : public views::MenuButton { 360 class BookmarkFolderButton : public BookmarkMenuButtonBase {
308 public: 361 public:
309 BookmarkFolderButton(const base::string16& title, 362 BookmarkFolderButton(const base::string16& title,
310 views::MenuButtonListener* menu_button_listener, 363 views::MenuButtonListener* menu_button_listener,
311 bool show_menu_marker) 364 bool show_menu_marker)
312 : MenuButton(title, menu_button_listener, show_menu_marker) { 365 : BookmarkMenuButtonBase(title, menu_button_listener, show_menu_marker) {
313 SetElideBehavior(kElideBehavior); 366 SetElideBehavior(kElideBehavior);
314 show_animation_.reset(new gfx::SlideAnimation(this)); 367 show_animation_.reset(new gfx::SlideAnimation(this));
315 if (!animations_enabled) { 368 if (!animations_enabled) {
316 // For some reason during testing the events generated by animating 369 // For some reason during testing the events generated by animating
317 // throw off the test. So, don't animate while testing. 370 // throw off the test. So, don't animate while testing.
318 show_animation_->Reset(1); 371 show_animation_->Reset(1);
319 } else { 372 } else {
320 show_animation_->Show(); 373 show_animation_->Show();
321 } 374 }
322 } 375 }
323 376
324 bool GetTooltipText(const gfx::Point& p, 377 bool GetTooltipText(const gfx::Point& p,
325 base::string16* tooltip) const override { 378 base::string16* tooltip) const override {
326 if (label()->GetPreferredSize().width() > label()->size().width()) 379 if (label()->GetPreferredSize().width() > label()->size().width())
327 *tooltip = GetText(); 380 *tooltip = GetText();
328 return !tooltip->empty(); 381 return !tooltip->empty();
329 } 382 }
330 383
384 bool OnMousePressed(const ui::MouseEvent& event) override {
385 if (event.IsOnlyLeftMouseButton()) {
386 // TODO(bruthig): The ACTION_PENDING triggering logic should be in
387 // MenuButton::OnPressed() however there is a bug with the pressed state
388 // logic in MenuButton. See http://crbug.com/567252.
389 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING);
390 }
391 return MenuButton::OnMousePressed(event);
392 }
393
331 bool IsTriggerableEventType(const ui::Event& e) override { 394 bool IsTriggerableEventType(const ui::Event& e) override {
332 // Bookmark folders handle normal menu button events (i.e., left click) as 395 // Bookmark folders handle normal menu button events (i.e., left click) as
333 // well as clicks to open bookmarks in new tabs that would otherwise be 396 // well as clicks to open bookmarks in new tabs that would otherwise be
334 // ignored. 397 // ignored.
335 return views::MenuButton::IsTriggerableEventType(e) || 398 return BookmarkMenuButtonBase::IsTriggerableEventType(e) ||
336 (e.IsMouseEvent() && 399 (e.IsMouseEvent() &&
337 ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB); 400 ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB);
338 } 401 }
339 402
340 private: 403 private:
341 scoped_ptr<gfx::SlideAnimation> show_animation_; 404 scoped_ptr<gfx::SlideAnimation> show_animation_;
342 405
343 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); 406 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton);
344 }; 407 };
345 408
346 // OverflowButton (chevron) -------------------------------------------------- 409 // OverflowButton (chevron) --------------------------------------------------
347 410
348 class OverflowButton : public views::MenuButton { 411 class OverflowButton : public BookmarkMenuButtonBase {
349 public: 412 public:
350 explicit OverflowButton(BookmarkBarView* owner) 413 explicit OverflowButton(BookmarkBarView* owner)
351 : MenuButton(base::string16(), owner, false), owner_(owner) {} 414 : BookmarkMenuButtonBase(base::string16(), owner, false), owner_(owner) {}
352 415
353 bool OnMousePressed(const ui::MouseEvent& e) override { 416 bool OnMousePressed(const ui::MouseEvent& e) override {
354 owner_->StopThrobbing(true); 417 owner_->StopThrobbing(true);
355 return views::MenuButton::OnMousePressed(e); 418 return BookmarkMenuButtonBase::OnMousePressed(e);
356 } 419 }
357 420
358 private: 421 private:
359 BookmarkBarView* owner_; 422 BookmarkBarView* owner_;
360 423
361 DISALLOW_COPY_AND_ASSIGN(OverflowButton); 424 DISALLOW_COPY_AND_ASSIGN(OverflowButton);
362 }; 425 };
363 426
364 void RecordAppLaunch(Profile* profile, const GURL& url) { 427 void RecordAppLaunch(Profile* profile, const GURL& url) {
365 const extensions::Extension* extension = 428 const extensions::Extension* extension =
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 return; 2143 return;
2081 apps_page_shortcut_->SetVisible(visible); 2144 apps_page_shortcut_->SetVisible(visible);
2082 UpdateBookmarksSeparatorVisibility(); 2145 UpdateBookmarksSeparatorVisibility();
2083 LayoutAndPaint(); 2146 LayoutAndPaint();
2084 } 2147 }
2085 2148
2086 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { 2149 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() {
2087 if (UpdateOtherAndManagedButtonsVisibility()) 2150 if (UpdateOtherAndManagedButtonsVisibility())
2088 LayoutAndPaint(); 2151 LayoutAndPaint();
2089 } 2152 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/animation/button_ink_drop_delegate.h » ('j') | ui/views/animation/ink_drop_animation_controller.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698