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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "content/public/browser/page_navigator.h" | 56 #include "content/public/browser/page_navigator.h" |
57 #include "content/public/browser/render_view_host.h" | 57 #include "content/public/browser/render_view_host.h" |
58 #include "content/public/browser/render_widget_host_view.h" | 58 #include "content/public/browser/render_widget_host_view.h" |
59 #include "content/public/browser/user_metrics.h" | 59 #include "content/public/browser/user_metrics.h" |
60 #include "content/public/browser/web_contents.h" | 60 #include "content/public/browser/web_contents.h" |
61 #include "content/public/common/page_transition_types.h" | 61 #include "content/public/common/page_transition_types.h" |
62 #include "grit/generated_resources.h" | 62 #include "grit/generated_resources.h" |
63 #include "grit/theme_resources.h" | 63 #include "grit/theme_resources.h" |
64 #include "grit/ui_resources.h" | 64 #include "grit/ui_resources.h" |
65 #include "ui/base/accessibility/accessible_view_state.h" | 65 #include "ui/base/accessibility/accessible_view_state.h" |
66 #include "ui/base/animation/slide_animation.h" | |
67 #include "ui/base/dragdrop/drag_utils.h" | 66 #include "ui/base/dragdrop/drag_utils.h" |
68 #include "ui/base/dragdrop/os_exchange_data.h" | 67 #include "ui/base/dragdrop/os_exchange_data.h" |
69 #include "ui/base/l10n/l10n_util.h" | 68 #include "ui/base/l10n/l10n_util.h" |
70 #include "ui/base/resource/resource_bundle.h" | 69 #include "ui/base/resource/resource_bundle.h" |
71 #include "ui/base/theme_provider.h" | 70 #include "ui/base/theme_provider.h" |
72 #include "ui/base/window_open_disposition.h" | 71 #include "ui/base/window_open_disposition.h" |
| 72 #include "ui/gfx/animation/slide_animation.h" |
73 #include "ui/gfx/canvas.h" | 73 #include "ui/gfx/canvas.h" |
74 #include "ui/gfx/text_elider.h" | 74 #include "ui/gfx/text_elider.h" |
75 #include "ui/views/button_drag_utils.h" | 75 #include "ui/views/button_drag_utils.h" |
76 #include "ui/views/controls/button/menu_button.h" | 76 #include "ui/views/controls/button/menu_button.h" |
77 #include "ui/views/controls/label.h" | 77 #include "ui/views/controls/label.h" |
78 #include "ui/views/controls/menu/menu_item_view.h" | 78 #include "ui/views/controls/menu/menu_item_view.h" |
79 #include "ui/views/drag_utils.h" | 79 #include "ui/views/drag_utils.h" |
80 #include "ui/views/metrics.h" | 80 #include "ui/views/metrics.h" |
81 #include "ui/views/view_constants.h" | 81 #include "ui/views/view_constants.h" |
82 #include "ui/views/widget/tooltip_manager.h" | 82 #include "ui/views/widget/tooltip_manager.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 // BookmarkButtonBase ----------------------------------------------- | 150 // BookmarkButtonBase ----------------------------------------------- |
151 | 151 |
152 // Base class for text buttons used on the bookmark bar. | 152 // Base class for text buttons used on the bookmark bar. |
153 | 153 |
154 class BookmarkButtonBase : public views::TextButton { | 154 class BookmarkButtonBase : public views::TextButton { |
155 public: | 155 public: |
156 BookmarkButtonBase(views::ButtonListener* listener, | 156 BookmarkButtonBase(views::ButtonListener* listener, |
157 const string16& title) | 157 const string16& title) |
158 : TextButton(listener, title) { | 158 : TextButton(listener, title) { |
159 show_animation_.reset(new ui::SlideAnimation(this)); | 159 show_animation_.reset(new gfx::SlideAnimation(this)); |
160 if (!animations_enabled) { | 160 if (!animations_enabled) { |
161 // For some reason during testing the events generated by animating | 161 // For some reason during testing the events generated by animating |
162 // throw off the test. So, don't animate while testing. | 162 // throw off the test. So, don't animate while testing. |
163 show_animation_->Reset(1); | 163 show_animation_->Reset(1); |
164 } else { | 164 } else { |
165 show_animation_->Show(); | 165 show_animation_->Show(); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | 169 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { |
170 return e.type() == ui::ET_GESTURE_TAP || | 170 return e.type() == ui::ET_GESTURE_TAP || |
171 e.type() == ui::ET_GESTURE_TAP_DOWN || | 171 e.type() == ui::ET_GESTURE_TAP_DOWN || |
172 event_utils::IsPossibleDispositionEvent(e); | 172 event_utils::IsPossibleDispositionEvent(e); |
173 } | 173 } |
174 | 174 |
175 private: | 175 private: |
176 scoped_ptr<ui::SlideAnimation> show_animation_; | 176 scoped_ptr<gfx::SlideAnimation> show_animation_; |
177 | 177 |
178 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); | 178 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); |
179 }; | 179 }; |
180 | 180 |
181 // BookmarkButton ------------------------------------------------------------- | 181 // BookmarkButton ------------------------------------------------------------- |
182 | 182 |
183 // Buttons used for the bookmarks on the bookmark bar. | 183 // Buttons used for the bookmarks on the bookmark bar. |
184 | 184 |
185 class BookmarkButton : public BookmarkButtonBase { | 185 class BookmarkButton : public BookmarkButtonBase { |
186 public: | 186 public: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 249 |
250 // Buttons used for folders on the bookmark bar, including the 'other folders' | 250 // Buttons used for folders on the bookmark bar, including the 'other folders' |
251 // button. | 251 // button. |
252 class BookmarkFolderButton : public views::MenuButton { | 252 class BookmarkFolderButton : public views::MenuButton { |
253 public: | 253 public: |
254 BookmarkFolderButton(views::ButtonListener* listener, | 254 BookmarkFolderButton(views::ButtonListener* listener, |
255 const string16& title, | 255 const string16& title, |
256 views::MenuButtonListener* menu_button_listener, | 256 views::MenuButtonListener* menu_button_listener, |
257 bool show_menu_marker) | 257 bool show_menu_marker) |
258 : MenuButton(listener, title, menu_button_listener, show_menu_marker) { | 258 : MenuButton(listener, title, menu_button_listener, show_menu_marker) { |
259 show_animation_.reset(new ui::SlideAnimation(this)); | 259 show_animation_.reset(new gfx::SlideAnimation(this)); |
260 if (!animations_enabled) { | 260 if (!animations_enabled) { |
261 // For some reason during testing the events generated by animating | 261 // For some reason during testing the events generated by animating |
262 // throw off the test. So, don't animate while testing. | 262 // throw off the test. So, don't animate while testing. |
263 show_animation_->Reset(1); | 263 show_animation_->Reset(1); |
264 } else { | 264 } else { |
265 show_animation_->Show(); | 265 show_animation_->Show(); |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 virtual bool GetTooltipText(const gfx::Point& p, | 269 virtual bool GetTooltipText(const gfx::Point& p, |
(...skipping 15 matching lines...) Expand all Loading... |
285 if (e.IsMouseEvent()) | 285 if (e.IsMouseEvent()) |
286 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; | 286 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; |
287 return false; | 287 return false; |
288 } | 288 } |
289 | 289 |
290 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 290 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
291 views::MenuButton::PaintButton(canvas, views::MenuButton::PB_NORMAL); | 291 views::MenuButton::PaintButton(canvas, views::MenuButton::PB_NORMAL); |
292 } | 292 } |
293 | 293 |
294 private: | 294 private: |
295 scoped_ptr<ui::SlideAnimation> show_animation_; | 295 scoped_ptr<gfx::SlideAnimation> show_animation_; |
296 | 296 |
297 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 297 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
298 }; | 298 }; |
299 | 299 |
300 // OverFlowButton (chevron) -------------------------------------------------- | 300 // OverFlowButton (chevron) -------------------------------------------------- |
301 | 301 |
302 class OverFlowButton : public views::MenuButton { | 302 class OverFlowButton : public views::MenuButton { |
303 public: | 303 public: |
304 explicit OverFlowButton(BookmarkBarView* owner) | 304 explicit OverFlowButton(BookmarkBarView* owner) |
305 : MenuButton(NULL, string16(), owner, false), | 305 : MenuButton(NULL, string16(), owner, false), |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 | 921 |
922 const char* BookmarkBarView::GetClassName() const { | 922 const char* BookmarkBarView::GetClassName() const { |
923 return kViewClassName; | 923 return kViewClassName; |
924 } | 924 } |
925 | 925 |
926 void BookmarkBarView::GetAccessibleState(ui::AccessibleViewState* state) { | 926 void BookmarkBarView::GetAccessibleState(ui::AccessibleViewState* state) { |
927 state->role = ui::AccessibilityTypes::ROLE_TOOLBAR; | 927 state->role = ui::AccessibilityTypes::ROLE_TOOLBAR; |
928 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS); | 928 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS); |
929 } | 929 } |
930 | 930 |
931 void BookmarkBarView::AnimationProgressed(const ui::Animation* animation) { | 931 void BookmarkBarView::AnimationProgressed(const gfx::Animation* animation) { |
932 // |browser_view_| can be NULL during tests. | 932 // |browser_view_| can be NULL during tests. |
933 if (browser_view_) | 933 if (browser_view_) |
934 browser_view_->ToolbarSizeChanged(true); | 934 browser_view_->ToolbarSizeChanged(true); |
935 } | 935 } |
936 | 936 |
937 void BookmarkBarView::AnimationEnded(const ui::Animation* animation) { | 937 void BookmarkBarView::AnimationEnded(const gfx::Animation* animation) { |
938 // |browser_view_| can be NULL during tests. | 938 // |browser_view_| can be NULL during tests. |
939 if (browser_view_) { | 939 if (browser_view_) { |
940 browser_view_->ToolbarSizeChanged(false); | 940 browser_view_->ToolbarSizeChanged(false); |
941 SchedulePaint(); | 941 SchedulePaint(); |
942 } | 942 } |
943 } | 943 } |
944 | 944 |
945 void BookmarkBarView::BookmarkMenuControllerDeleted( | 945 void BookmarkBarView::BookmarkMenuControllerDeleted( |
946 BookmarkMenuController* controller) { | 946 BookmarkMenuController* controller) { |
947 if (controller == bookmark_menu_) | 947 if (controller == bookmark_menu_) |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 | 1285 |
1286 bookmarks_separator_view_ = new ButtonSeparatorView(); | 1286 bookmarks_separator_view_ = new ButtonSeparatorView(); |
1287 AddChildView(bookmarks_separator_view_); | 1287 AddChildView(bookmarks_separator_view_); |
1288 UpdateBookmarksSeparatorVisibility(); | 1288 UpdateBookmarksSeparatorVisibility(); |
1289 | 1289 |
1290 instructions_ = new BookmarkBarInstructionsView(this); | 1290 instructions_ = new BookmarkBarInstructionsView(this); |
1291 AddChildView(instructions_); | 1291 AddChildView(instructions_); |
1292 | 1292 |
1293 set_context_menu_controller(this); | 1293 set_context_menu_controller(this); |
1294 | 1294 |
1295 size_animation_.reset(new ui::SlideAnimation(this)); | 1295 size_animation_.reset(new gfx::SlideAnimation(this)); |
1296 | 1296 |
1297 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); | 1297 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); |
1298 if (model_) { | 1298 if (model_) { |
1299 model_->AddObserver(this); | 1299 model_->AddObserver(this); |
1300 if (model_->loaded()) | 1300 if (model_->loaded()) |
1301 Loaded(model_, false); | 1301 Loaded(model_, false); |
1302 // else case: we'll receive notification back from the BookmarkModel when | 1302 // else case: we'll receive notification back from the BookmarkModel when |
1303 // done loading, then we'll populate the bar. | 1303 // done loading, then we'll populate the bar. |
1304 } | 1304 } |
1305 } | 1305 } |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 DCHECK(apps_page_shortcut_); | 1858 DCHECK(apps_page_shortcut_); |
1859 // Only perform layout if required. | 1859 // Only perform layout if required. |
1860 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 1860 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
1861 browser_->profile()); | 1861 browser_->profile()); |
1862 if (apps_page_shortcut_->visible() == visible) | 1862 if (apps_page_shortcut_->visible() == visible) |
1863 return; | 1863 return; |
1864 apps_page_shortcut_->SetVisible(visible); | 1864 apps_page_shortcut_->SetVisible(visible); |
1865 UpdateBookmarksSeparatorVisibility(); | 1865 UpdateBookmarksSeparatorVisibility(); |
1866 Layout(); | 1866 Layout(); |
1867 } | 1867 } |
OLD | NEW |