| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/thread_task_runner_handle.h" | 24 #include "base/thread_task_runner_handle.h" |
| 24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 25 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 26 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 26 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 27 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 #include "ui/base/material_design/material_design_controller.h" | 82 #include "ui/base/material_design/material_design_controller.h" |
| 82 #include "ui/base/page_transition_types.h" | 83 #include "ui/base/page_transition_types.h" |
| 83 #include "ui/base/resource/resource_bundle.h" | 84 #include "ui/base/resource/resource_bundle.h" |
| 84 #include "ui/base/theme_provider.h" | 85 #include "ui/base/theme_provider.h" |
| 85 #include "ui/base/window_open_disposition.h" | 86 #include "ui/base/window_open_disposition.h" |
| 86 #include "ui/compositor/paint_recorder.h" | 87 #include "ui/compositor/paint_recorder.h" |
| 87 #include "ui/gfx/animation/slide_animation.h" | 88 #include "ui/gfx/animation/slide_animation.h" |
| 88 #include "ui/gfx/canvas.h" | 89 #include "ui/gfx/canvas.h" |
| 89 #include "ui/gfx/color_utils.h" | 90 #include "ui/gfx/color_utils.h" |
| 90 #include "ui/gfx/favicon_size.h" | 91 #include "ui/gfx/favicon_size.h" |
| 92 #include "ui/gfx/geometry/rect.h" |
| 91 #include "ui/gfx/paint_vector_icon.h" | 93 #include "ui/gfx/paint_vector_icon.h" |
| 92 #include "ui/gfx/scoped_canvas.h" | 94 #include "ui/gfx/scoped_canvas.h" |
| 93 #include "ui/gfx/text_constants.h" | 95 #include "ui/gfx/text_constants.h" |
| 94 #include "ui/gfx/text_elider.h" | 96 #include "ui/gfx/text_elider.h" |
| 95 #include "ui/gfx/vector_icons_public.h" | 97 #include "ui/gfx/vector_icons_public.h" |
| 96 #include "ui/resources/grit/ui_resources.h" | 98 #include "ui/resources/grit/ui_resources.h" |
| 97 #include "ui/views/animation/button_ink_drop_delegate.h" | 99 #include "ui/views/animation/button_ink_drop_delegate.h" |
| 98 #include "ui/views/animation/flood_fill_ink_drop_animation.h" | 100 #include "ui/views/animation/flood_fill_ink_drop_animation.h" |
| 99 #include "ui/views/animation/ink_drop_hover.h" | 101 #include "ui/views/animation/ink_drop_hover.h" |
| 100 #include "ui/views/button_drag_utils.h" | 102 #include "ui/views/button_drag_utils.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 bool animations_enabled = true; | 184 bool animations_enabled = true; |
| 183 | 185 |
| 184 gfx::ImageSkia* GetImageSkiaNamed(int id) { | 186 gfx::ImageSkia* GetImageSkiaNamed(int id) { |
| 185 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | 187 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); |
| 186 } | 188 } |
| 187 | 189 |
| 188 int GetHorizontalMargin() { | 190 int GetHorizontalMargin() { |
| 189 return kHorizontalMargin[ui::MaterialDesignController::GetMode()]; | 191 return kHorizontalMargin[ui::MaterialDesignController::GetMode()]; |
| 190 } | 192 } |
| 191 | 193 |
| 192 gfx::Size CalculateInkDropSize(const gfx::Size& button_size) { | 194 gfx::Rect CalculateInkDropBounds(const gfx::Size& size) { |
| 193 gfx::Size ink_drop_size(button_size); | 195 gfx::Rect ink_drop_bounds(size); |
| 194 ink_drop_size.Enlarge(0, -2); | 196 ink_drop_bounds.Inset(0, 1); |
| 195 return ink_drop_size; | 197 return ink_drop_bounds; |
| 196 } | 198 } |
| 197 | 199 |
| 198 // BookmarkButtonBase ----------------------------------------------- | 200 // BookmarkButtonBase ----------------------------------------------- |
| 199 | 201 |
| 200 // Base class for non-menu hosting buttons used on the bookmark bar. | 202 // Base class for non-menu hosting buttons used on the bookmark bar. |
| 201 | 203 |
| 202 class BookmarkButtonBase : public views::LabelButton { | 204 class BookmarkButtonBase : public views::LabelButton { |
| 203 public: | 205 public: |
| 204 BookmarkButtonBase(views::ButtonListener* listener, | 206 BookmarkButtonBase(views::ButtonListener* listener, |
| 205 const base::string16& title) | 207 const base::string16& title) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 230 kButtonPaddingHorizontal)); | 232 kButtonPaddingHorizontal)); |
| 231 return border; | 233 return border; |
| 232 } | 234 } |
| 233 | 235 |
| 234 bool IsTriggerableEvent(const ui::Event& e) override { | 236 bool IsTriggerableEvent(const ui::Event& e) override { |
| 235 return e.type() == ui::ET_GESTURE_TAP || | 237 return e.type() == ui::ET_GESTURE_TAP || |
| 236 e.type() == ui::ET_GESTURE_TAP_DOWN || | 238 e.type() == ui::ET_GESTURE_TAP_DOWN || |
| 237 event_utils::IsPossibleDispositionEvent(e); | 239 event_utils::IsPossibleDispositionEvent(e); |
| 238 } | 240 } |
| 239 | 241 |
| 240 std::unique_ptr<views::InkDropAnimation> CreateInkDropAnimation() | 242 scoped_ptr<views::InkDropAnimation> CreateInkDropAnimation() const override { |
| 241 const override { | 243 return make_scoped_ptr(new views::FloodFillInkDropAnimation( |
| 242 return base::WrapUnique(new views::FloodFillInkDropAnimation( | 244 CalculateInkDropBounds(size()), GetInkDropCenter(), |
| 243 CalculateInkDropSize(size()), GetInkDropCenter(), | |
| 244 GetInkDropBaseColor())); | 245 GetInkDropBaseColor())); |
| 245 } | 246 } |
| 246 | 247 |
| 247 std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override { | 248 scoped_ptr<views::InkDropHover> CreateInkDropHover() const override { |
| 248 if (!ShouldShowInkDropHover()) | 249 if (!ShouldShowInkDropHover()) |
| 249 return nullptr; | 250 return nullptr; |
| 250 return base::WrapUnique( | 251 |
| 251 new views::InkDropHover(CalculateInkDropSize(size()), 0, | 252 const gfx::Rect bounds = CalculateInkDropBounds(size()); |
| 252 GetInkDropCenter(), GetInkDropBaseColor())); | 253 return make_scoped_ptr(new views::InkDropHover( |
| 254 bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor())); |
| 253 } | 255 } |
| 254 | 256 |
| 255 SkColor GetInkDropBaseColor() const override { | 257 SkColor GetInkDropBaseColor() const override { |
| 256 return GetThemeProvider()->GetColor( | 258 return GetThemeProvider()->GetColor( |
| 257 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 259 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); |
| 258 } | 260 } |
| 259 | 261 |
| 260 private: | 262 private: |
| 261 std::unique_ptr<gfx::SlideAnimation> show_animation_; | 263 scoped_ptr<gfx::SlideAnimation> show_animation_; |
| 262 | 264 |
| 263 // Controls the visual feedback for the button state. | 265 // Controls the visual feedback for the button state. |
| 264 views::ButtonInkDropDelegate ink_drop_delegate_; | 266 views::ButtonInkDropDelegate ink_drop_delegate_; |
| 265 | 267 |
| 266 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); | 268 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); |
| 267 }; | 269 }; |
| 268 | 270 |
| 269 // BookmarkButton ------------------------------------------------------------- | 271 // BookmarkButton ------------------------------------------------------------- |
| 270 | 272 |
| 271 // Buttons used for the bookmarks on the bookmark bar. | 273 // Buttons used for the bookmarks on the bookmark bar. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 class BookmarkMenuButtonBase : public views::MenuButton { | 333 class BookmarkMenuButtonBase : public views::MenuButton { |
| 332 public: | 334 public: |
| 333 BookmarkMenuButtonBase(const base::string16& title, | 335 BookmarkMenuButtonBase(const base::string16& title, |
| 334 views::MenuButtonListener* menu_button_listener, | 336 views::MenuButtonListener* menu_button_listener, |
| 335 bool show_menu_marker) | 337 bool show_menu_marker) |
| 336 : MenuButton(title, menu_button_listener, show_menu_marker), | 338 : MenuButton(title, menu_button_listener, show_menu_marker), |
| 337 ink_drop_delegate_(this, this) { | 339 ink_drop_delegate_(this, this) { |
| 338 set_ink_drop_delegate(&ink_drop_delegate_); | 340 set_ink_drop_delegate(&ink_drop_delegate_); |
| 339 } | 341 } |
| 340 | 342 |
| 341 std::unique_ptr<views::InkDropAnimation> CreateInkDropAnimation() | 343 scoped_ptr<views::InkDropAnimation> CreateInkDropAnimation() const override { |
| 342 const override { | 344 return make_scoped_ptr(new views::FloodFillInkDropAnimation( |
| 343 return base::WrapUnique(new views::FloodFillInkDropAnimation( | 345 CalculateInkDropBounds(size()), GetInkDropCenter(), |
| 344 CalculateInkDropSize(size()), GetInkDropCenter(), | |
| 345 GetInkDropBaseColor())); | 346 GetInkDropBaseColor())); |
| 346 } | 347 } |
| 347 | 348 |
| 348 std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override { | 349 scoped_ptr<views::InkDropHover> CreateInkDropHover() const override { |
| 349 if (!ShouldShowInkDropHover()) | 350 if (!ShouldShowInkDropHover()) |
| 350 return nullptr; | 351 return nullptr; |
| 351 return base::WrapUnique( | 352 |
| 352 new views::InkDropHover(CalculateInkDropSize(size()), 0, | 353 const gfx::Rect bounds = CalculateInkDropBounds(size()); |
| 353 GetInkDropCenter(), GetInkDropBaseColor())); | 354 return make_scoped_ptr(new views::InkDropHover( |
| 355 bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor())); |
| 354 } | 356 } |
| 355 | 357 |
| 356 SkColor GetInkDropBaseColor() const override { | 358 SkColor GetInkDropBaseColor() const override { |
| 357 return GetThemeProvider()->GetColor( | 359 return GetThemeProvider()->GetColor( |
| 358 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 360 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); |
| 359 } | 361 } |
| 360 | 362 |
| 361 private: | 363 private: |
| 362 // Controls the visual feedback for the button state. | 364 // Controls the visual feedback for the button state. |
| 363 views::ButtonInkDropDelegate ink_drop_delegate_; | 365 views::ButtonInkDropDelegate ink_drop_delegate_; |
| (...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 return; | 2163 return; |
| 2162 apps_page_shortcut_->SetVisible(visible); | 2164 apps_page_shortcut_->SetVisible(visible); |
| 2163 UpdateBookmarksSeparatorVisibility(); | 2165 UpdateBookmarksSeparatorVisibility(); |
| 2164 LayoutAndPaint(); | 2166 LayoutAndPaint(); |
| 2165 } | 2167 } |
| 2166 | 2168 |
| 2167 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2169 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
| 2168 if (UpdateOtherAndManagedButtonsVisibility()) | 2170 if (UpdateOtherAndManagedButtonsVisibility()) |
| 2169 LayoutAndPaint(); | 2171 LayoutAndPaint(); |
| 2170 } | 2172 } |
| OLD | NEW |