| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 // TODO(bruthig): Inject the color instead of assuming a ThemeProvider is |
| 232 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 246 // always available. Fall back on LabelButton::GetInkDropBaseColor() so as |
| 247 // to avoid difficult to track down crashes. |
| 248 return GetThemeProvider() |
| 249 ? GetThemeProvider()->GetColor( |
| 250 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON) |
| 251 : views::LabelButton::GetInkDropBaseColor(); |
| 233 } | 252 } |
| 234 | 253 |
| 235 private: | 254 private: |
| 236 scoped_ptr<gfx::SlideAnimation> show_animation_; | 255 scoped_ptr<gfx::SlideAnimation> show_animation_; |
| 237 | 256 |
| 238 // Controls the visual feedback for the button state. | 257 // Controls the visual feedback for the button state. |
| 239 views::ButtonInkDropDelegate ink_drop_delegate_; | 258 views::ButtonInkDropDelegate ink_drop_delegate_; |
| 240 | 259 |
| 241 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); | 260 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); |
| 242 }; | 261 }; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 312 |
| 294 const char* GetClassName() const override { return kViewClassName; } | 313 const char* GetClassName() const override { return kViewClassName; } |
| 295 | 314 |
| 296 private: | 315 private: |
| 297 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); | 316 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); |
| 298 }; | 317 }; |
| 299 | 318 |
| 300 // static | 319 // static |
| 301 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; | 320 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; |
| 302 | 321 |
| 322 // BookmarkMenuButtonBase ----------------------------------------------------- |
| 323 |
| 324 // Base class for menu hosting buttons used on the bookmark bar. |
| 325 class BookmarkMenuButtonBase : public views::MenuButton { |
| 326 public: |
| 327 BookmarkMenuButtonBase(const base::string16& title, |
| 328 views::MenuButtonListener* menu_button_listener, |
| 329 bool show_menu_marker) |
| 330 : MenuButton(title, menu_button_listener, show_menu_marker), |
| 331 ink_drop_delegate_(this, this) { |
| 332 set_ink_drop_delegate(&ink_drop_delegate_); |
| 333 } |
| 334 |
| 335 scoped_ptr<views::InkDropAnimation> CreateInkDropAnimation() const override { |
| 336 return make_scoped_ptr(new views::FloodFillInkDropAnimation( |
| 337 size(), GetInkDropCenter(), GetInkDropBaseColor())); |
| 338 } |
| 339 |
| 340 scoped_ptr<views::InkDropHover> CreateInkDropHover() const override { |
| 341 if (!ShouldShowInkDropHover()) |
| 342 return nullptr; |
| 343 return make_scoped_ptr(new views::InkDropHover( |
| 344 size(), 0, GetInkDropCenter(), GetInkDropBaseColor())); |
| 345 } |
| 346 |
| 347 SkColor GetInkDropBaseColor() const override { |
| 348 return GetThemeProvider() |
| 349 ? GetThemeProvider()->GetColor( |
| 350 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON) |
| 351 : views::LabelButton::GetInkDropBaseColor(); |
| 352 } |
| 353 |
| 354 private: |
| 355 // Controls the visual feedback for the button state. |
| 356 views::ButtonInkDropDelegate ink_drop_delegate_; |
| 357 |
| 358 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuButtonBase); |
| 359 }; |
| 360 |
| 303 // BookmarkFolderButton ------------------------------------------------------- | 361 // BookmarkFolderButton ------------------------------------------------------- |
| 304 | 362 |
| 305 // Buttons used for folders on the bookmark bar, including the 'other folders' | 363 // Buttons used for folders on the bookmark bar, including the 'other folders' |
| 306 // button. | 364 // button. |
| 307 class BookmarkFolderButton : public views::MenuButton { | 365 class BookmarkFolderButton : public BookmarkMenuButtonBase { |
| 308 public: | 366 public: |
| 309 BookmarkFolderButton(const base::string16& title, | 367 BookmarkFolderButton(const base::string16& title, |
| 310 views::MenuButtonListener* menu_button_listener, | 368 views::MenuButtonListener* menu_button_listener, |
| 311 bool show_menu_marker) | 369 bool show_menu_marker) |
| 312 : MenuButton(title, menu_button_listener, show_menu_marker) { | 370 : BookmarkMenuButtonBase(title, menu_button_listener, show_menu_marker) { |
| 313 SetElideBehavior(kElideBehavior); | 371 SetElideBehavior(kElideBehavior); |
| 314 show_animation_.reset(new gfx::SlideAnimation(this)); | 372 show_animation_.reset(new gfx::SlideAnimation(this)); |
| 315 if (!animations_enabled) { | 373 if (!animations_enabled) { |
| 316 // For some reason during testing the events generated by animating | 374 // For some reason during testing the events generated by animating |
| 317 // throw off the test. So, don't animate while testing. | 375 // throw off the test. So, don't animate while testing. |
| 318 show_animation_->Reset(1); | 376 show_animation_->Reset(1); |
| 319 } else { | 377 } else { |
| 320 show_animation_->Show(); | 378 show_animation_->Show(); |
| 321 } | 379 } |
| 322 } | 380 } |
| 323 | 381 |
| 324 bool GetTooltipText(const gfx::Point& p, | 382 bool GetTooltipText(const gfx::Point& p, |
| 325 base::string16* tooltip) const override { | 383 base::string16* tooltip) const override { |
| 326 if (label()->GetPreferredSize().width() > label()->size().width()) | 384 if (label()->GetPreferredSize().width() > label()->size().width()) |
| 327 *tooltip = GetText(); | 385 *tooltip = GetText(); |
| 328 return !tooltip->empty(); | 386 return !tooltip->empty(); |
| 329 } | 387 } |
| 330 | 388 |
| 389 bool OnMousePressed(const ui::MouseEvent& event) override { |
| 390 if (event.IsOnlyLeftMouseButton()) { |
| 391 // TODO(bruthig): The ACTION_PENDING triggering logic should be in |
| 392 // MenuButton::OnPressed() however there is a bug with the pressed state |
| 393 // logic in MenuButton. See http://crbug.com/567252. |
| 394 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); |
| 395 } |
| 396 return MenuButton::OnMousePressed(event); |
| 397 } |
| 398 |
| 331 bool IsTriggerableEventType(const ui::Event& e) override { | 399 bool IsTriggerableEventType(const ui::Event& e) override { |
| 332 // Bookmark folders handle normal menu button events (i.e., left click) as | 400 // 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 | 401 // well as clicks to open bookmarks in new tabs that would otherwise be |
| 334 // ignored. | 402 // ignored. |
| 335 return views::MenuButton::IsTriggerableEventType(e) || | 403 return BookmarkMenuButtonBase::IsTriggerableEventType(e) || |
| 336 (e.IsMouseEvent() && | 404 (e.IsMouseEvent() && |
| 337 ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB); | 405 ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB); |
| 338 } | 406 } |
| 339 | 407 |
| 340 private: | 408 private: |
| 341 scoped_ptr<gfx::SlideAnimation> show_animation_; | 409 scoped_ptr<gfx::SlideAnimation> show_animation_; |
| 342 | 410 |
| 343 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 411 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
| 344 }; | 412 }; |
| 345 | 413 |
| 346 // OverflowButton (chevron) -------------------------------------------------- | 414 // OverflowButton (chevron) -------------------------------------------------- |
| 347 | 415 |
| 348 class OverflowButton : public views::MenuButton { | 416 class OverflowButton : public BookmarkMenuButtonBase { |
| 349 public: | 417 public: |
| 350 explicit OverflowButton(BookmarkBarView* owner) | 418 explicit OverflowButton(BookmarkBarView* owner) |
| 351 : MenuButton(base::string16(), owner, false), owner_(owner) {} | 419 : BookmarkMenuButtonBase(base::string16(), owner, false), owner_(owner) {} |
| 352 | 420 |
| 353 bool OnMousePressed(const ui::MouseEvent& e) override { | 421 bool OnMousePressed(const ui::MouseEvent& e) override { |
| 354 owner_->StopThrobbing(true); | 422 owner_->StopThrobbing(true); |
| 355 return views::MenuButton::OnMousePressed(e); | 423 return BookmarkMenuButtonBase::OnMousePressed(e); |
| 356 } | 424 } |
| 357 | 425 |
| 358 private: | 426 private: |
| 359 BookmarkBarView* owner_; | 427 BookmarkBarView* owner_; |
| 360 | 428 |
| 361 DISALLOW_COPY_AND_ASSIGN(OverflowButton); | 429 DISALLOW_COPY_AND_ASSIGN(OverflowButton); |
| 362 }; | 430 }; |
| 363 | 431 |
| 364 void RecordAppLaunch(Profile* profile, const GURL& url) { | 432 void RecordAppLaunch(Profile* profile, const GURL& url) { |
| 365 const extensions::Extension* extension = | 433 const extensions::Extension* extension = |
| (...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 return; | 2148 return; |
| 2081 apps_page_shortcut_->SetVisible(visible); | 2149 apps_page_shortcut_->SetVisible(visible); |
| 2082 UpdateBookmarksSeparatorVisibility(); | 2150 UpdateBookmarksSeparatorVisibility(); |
| 2083 LayoutAndPaint(); | 2151 LayoutAndPaint(); |
| 2084 } | 2152 } |
| 2085 | 2153 |
| 2086 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2154 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
| 2087 if (UpdateOtherAndManagedButtonsVisibility()) | 2155 if (UpdateOtherAndManagedButtonsVisibility()) |
| 2088 LayoutAndPaint(); | 2156 LayoutAndPaint(); |
| 2089 } | 2157 } |
| OLD | NEW |