| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/bookmark_bar_view.h" | 5 #include "chrome/browser/views/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> |
| 11 | 11 |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "app/os_exchange_data.h" | 13 #include "app/os_exchange_data.h" |
| 14 #include "app/resource_bundle.h" | 14 #include "app/resource_bundle.h" |
| 15 #include "app/slide_animation.h" | |
| 16 #include "app/text_elider.h" | 15 #include "app/text_elider.h" |
| 17 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
| 18 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 19 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_model.h" | 19 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_utils.h" | 20 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 22 #include "chrome/browser/browser_shutdown.h" | 21 #include "chrome/browser/browser_shutdown.h" |
| 23 #include "chrome/browser/importer/importer_data_types.h" | 22 #include "chrome/browser/importer/importer_data_types.h" |
| 24 #include "chrome/browser/metrics/user_metrics.h" | 23 #include "chrome/browser/metrics/user_metrics.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 #include "chrome/browser/ui/views/event_utils.h" | 35 #include "chrome/browser/ui/views/event_utils.h" |
| 37 #include "chrome/browser/ui/views/frame/browser_view.h" | 36 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 38 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 37 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 39 #include "chrome/common/notification_service.h" | 38 #include "chrome/common/notification_service.h" |
| 40 #include "chrome/common/page_transition_types.h" | 39 #include "chrome/common/page_transition_types.h" |
| 41 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 42 #include "gfx/canvas_skia.h" | 41 #include "gfx/canvas_skia.h" |
| 43 #include "grit/app_resources.h" | 42 #include "grit/app_resources.h" |
| 44 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 45 #include "grit/theme_resources.h" | 44 #include "grit/theme_resources.h" |
| 45 #include "ui/base/animation/slide_animation.h" |
| 46 #include "views/controls/button/menu_button.h" | 46 #include "views/controls/button/menu_button.h" |
| 47 #include "views/controls/label.h" | 47 #include "views/controls/label.h" |
| 48 #include "views/controls/menu/menu_item_view.h" | 48 #include "views/controls/menu/menu_item_view.h" |
| 49 #include "views/drag_utils.h" | 49 #include "views/drag_utils.h" |
| 50 #include "views/view_constants.h" | 50 #include "views/view_constants.h" |
| 51 #include "views/widget/tooltip_manager.h" | 51 #include "views/widget/tooltip_manager.h" |
| 52 #include "views/widget/widget.h" | 52 #include "views/widget/widget.h" |
| 53 #include "views/window/window.h" | 53 #include "views/window/window.h" |
| 54 | 54 |
| 55 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 class BookmarkButton : public views::TextButton { | 173 class BookmarkButton : public views::TextButton { |
| 174 public: | 174 public: |
| 175 BookmarkButton(views::ButtonListener* listener, | 175 BookmarkButton(views::ButtonListener* listener, |
| 176 const GURL& url, | 176 const GURL& url, |
| 177 const std::wstring& title, | 177 const std::wstring& title, |
| 178 Profile* profile) | 178 Profile* profile) |
| 179 : TextButton(listener, title), | 179 : TextButton(listener, title), |
| 180 url_(url), | 180 url_(url), |
| 181 profile_(profile) { | 181 profile_(profile) { |
| 182 show_animation_.reset(new SlideAnimation(this)); | 182 show_animation_.reset(new ui::SlideAnimation(this)); |
| 183 if (BookmarkBarView::testing_) { | 183 if (BookmarkBarView::testing_) { |
| 184 // For some reason during testing the events generated by animating | 184 // For some reason during testing the events generated by animating |
| 185 // throw off the test. So, don't animate while testing. | 185 // throw off the test. So, don't animate while testing. |
| 186 show_animation_->Reset(1); | 186 show_animation_->Reset(1); |
| 187 } else { | 187 } else { |
| 188 show_animation_->Show(); | 188 show_animation_->Show(); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { | 192 bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { |
| 193 gfx::Point location(p); | 193 gfx::Point location(p); |
| 194 ConvertPointToScreen(this, &location); | 194 ConvertPointToScreen(this, &location); |
| 195 *tooltip = CreateToolTipForURLAndTitle(location, url_, text(), | 195 *tooltip = CreateToolTipForURLAndTitle(location, url_, text(), |
| 196 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); | 196 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); |
| 197 return !tooltip->empty(); | 197 return !tooltip->empty(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 virtual bool IsTriggerableEvent(const views::MouseEvent& e) { | 200 virtual bool IsTriggerableEvent(const views::MouseEvent& e) { |
| 201 return event_utils::IsPossibleDispositionEvent(e); | 201 return event_utils::IsPossibleDispositionEvent(e); |
| 202 } | 202 } |
| 203 | 203 |
| 204 private: | 204 private: |
| 205 const GURL& url_; | 205 const GURL& url_; |
| 206 Profile* profile_; | 206 Profile* profile_; |
| 207 scoped_ptr<SlideAnimation> show_animation_; | 207 scoped_ptr<ui::SlideAnimation> show_animation_; |
| 208 | 208 |
| 209 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 209 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 // BookmarkFolderButton ------------------------------------------------------- | 212 // BookmarkFolderButton ------------------------------------------------------- |
| 213 | 213 |
| 214 // Buttons used for folders on the bookmark bar, including the 'other folders' | 214 // Buttons used for folders on the bookmark bar, including the 'other folders' |
| 215 // button. | 215 // button. |
| 216 class BookmarkFolderButton : public views::MenuButton { | 216 class BookmarkFolderButton : public views::MenuButton { |
| 217 public: | 217 public: |
| 218 BookmarkFolderButton(views::ButtonListener* listener, | 218 BookmarkFolderButton(views::ButtonListener* listener, |
| 219 const std::wstring& title, | 219 const std::wstring& title, |
| 220 views::ViewMenuDelegate* menu_delegate, | 220 views::ViewMenuDelegate* menu_delegate, |
| 221 bool show_menu_marker) | 221 bool show_menu_marker) |
| 222 : MenuButton(listener, title, menu_delegate, show_menu_marker) { | 222 : MenuButton(listener, title, menu_delegate, show_menu_marker) { |
| 223 show_animation_.reset(new SlideAnimation(this)); | 223 show_animation_.reset(new ui::SlideAnimation(this)); |
| 224 if (BookmarkBarView::testing_) { | 224 if (BookmarkBarView::testing_) { |
| 225 // For some reason during testing the events generated by animating | 225 // For some reason during testing the events generated by animating |
| 226 // throw off the test. So, don't animate while testing. | 226 // throw off the test. So, don't animate while testing. |
| 227 show_animation_->Reset(1); | 227 show_animation_->Reset(1); |
| 228 } else { | 228 } else { |
| 229 show_animation_->Show(); | 229 show_animation_->Show(); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 virtual bool IsTriggerableEvent(const views::MouseEvent& e) { | 233 virtual bool IsTriggerableEvent(const views::MouseEvent& e) { |
| 234 // Left clicks should show the menu contents and right clicks should show | 234 // Left clicks should show the menu contents and right clicks should show |
| 235 // the context menu. They should not trigger the opening of underlying urls. | 235 // the context menu. They should not trigger the opening of underlying urls. |
| 236 if (e.GetFlags() == views::MouseEvent::EF_LEFT_BUTTON_DOWN || | 236 if (e.GetFlags() == views::MouseEvent::EF_LEFT_BUTTON_DOWN || |
| 237 e.GetFlags() == views::MouseEvent::EF_RIGHT_BUTTON_DOWN) | 237 e.GetFlags() == views::MouseEvent::EF_RIGHT_BUTTON_DOWN) |
| 238 return false; | 238 return false; |
| 239 | 239 |
| 240 WindowOpenDisposition disposition( | 240 WindowOpenDisposition disposition( |
| 241 event_utils::DispositionFromEventFlags(e.GetFlags())); | 241 event_utils::DispositionFromEventFlags(e.GetFlags())); |
| 242 return disposition != CURRENT_TAB; | 242 return disposition != CURRENT_TAB; |
| 243 } | 243 } |
| 244 | 244 |
| 245 virtual void Paint(gfx::Canvas* canvas) { | 245 virtual void Paint(gfx::Canvas* canvas) { |
| 246 views::MenuButton::Paint(canvas, false); | 246 views::MenuButton::Paint(canvas, false); |
| 247 } | 247 } |
| 248 | 248 |
| 249 private: | 249 private: |
| 250 scoped_ptr<SlideAnimation> show_animation_; | 250 scoped_ptr<ui::SlideAnimation> show_animation_; |
| 251 | 251 |
| 252 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 252 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
| 253 }; | 253 }; |
| 254 | 254 |
| 255 // OverFlowButton (chevron) -------------------------------------------------- | 255 // OverFlowButton (chevron) -------------------------------------------------- |
| 256 | 256 |
| 257 class OverFlowButton : public views::MenuButton { | 257 class OverFlowButton : public views::MenuButton { |
| 258 public: | 258 public: |
| 259 explicit OverFlowButton(BookmarkBarView* owner) | 259 explicit OverFlowButton(BookmarkBarView* owner) |
| 260 : MenuButton(NULL, std::wstring(), owner, false), | 260 : MenuButton(NULL, std::wstring(), owner, false), |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 // When on the New Tab Page with no infobar, animate the overlap between the | 772 // When on the New Tab Page with no infobar, animate the overlap between the |
| 773 // attached and detached states. | 773 // attached and detached states. |
| 774 return static_cast<int>(static_cast<double>(kToolbarOverlap) * | 774 return static_cast<int>(static_cast<double>(kToolbarOverlap) * |
| 775 size_animation_->GetCurrentValue()); | 775 size_animation_->GetCurrentValue()); |
| 776 } | 776 } |
| 777 | 777 |
| 778 bool BookmarkBarView::is_animating() { | 778 bool BookmarkBarView::is_animating() { |
| 779 return size_animation_->is_animating(); | 779 return size_animation_->is_animating(); |
| 780 } | 780 } |
| 781 | 781 |
| 782 void BookmarkBarView::AnimationProgressed(const Animation* animation) { | 782 void BookmarkBarView::AnimationProgressed(const ui::Animation* animation) { |
| 783 if (browser_) | 783 if (browser_) |
| 784 browser_->ToolbarSizeChanged(true); | 784 browser_->ToolbarSizeChanged(true); |
| 785 } | 785 } |
| 786 | 786 |
| 787 void BookmarkBarView::AnimationEnded(const Animation* animation) { | 787 void BookmarkBarView::AnimationEnded(const ui::Animation* animation) { |
| 788 if (browser_) | 788 if (browser_) |
| 789 browser_->ToolbarSizeChanged(false); | 789 browser_->ToolbarSizeChanged(false); |
| 790 | 790 |
| 791 SchedulePaint(); | 791 SchedulePaint(); |
| 792 } | 792 } |
| 793 | 793 |
| 794 void BookmarkBarView::BookmarkMenuDeleted(BookmarkMenuController* controller) { | 794 void BookmarkBarView::BookmarkMenuDeleted(BookmarkMenuController* controller) { |
| 795 if (controller == bookmark_menu_) | 795 if (controller == bookmark_menu_) |
| 796 bookmark_menu_ = NULL; | 796 bookmark_menu_ = NULL; |
| 797 else if (controller == bookmark_drop_menu_) | 797 else if (controller == bookmark_drop_menu_) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 bookmarks_separator_view_ = new ButtonSeparatorView(); | 916 bookmarks_separator_view_ = new ButtonSeparatorView(); |
| 917 bookmarks_separator_view_->SetAccessibleName( | 917 bookmarks_separator_view_->SetAccessibleName( |
| 918 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR))); | 918 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR))); |
| 919 AddChildView(bookmarks_separator_view_); | 919 AddChildView(bookmarks_separator_view_); |
| 920 | 920 |
| 921 instructions_ = new BookmarkBarInstructionsView(this); | 921 instructions_ = new BookmarkBarInstructionsView(this); |
| 922 AddChildView(instructions_); | 922 AddChildView(instructions_); |
| 923 | 923 |
| 924 SetContextMenuController(this); | 924 SetContextMenuController(this); |
| 925 | 925 |
| 926 size_animation_.reset(new SlideAnimation(this)); | 926 size_animation_.reset(new ui::SlideAnimation(this)); |
| 927 } | 927 } |
| 928 | 928 |
| 929 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { | 929 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { |
| 930 MenuButton* button = new BookmarkFolderButton( | 930 MenuButton* button = new BookmarkFolderButton( |
| 931 this, | 931 this, |
| 932 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)), | 932 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)), |
| 933 this, | 933 this, |
| 934 false); | 934 false); |
| 935 button->SetID(VIEW_ID_OTHER_BOOKMARKS); | 935 button->SetID(VIEW_ID_OTHER_BOOKMARKS); |
| 936 button->SetIcon(GetGroupIcon()); | 936 button->SetIcon(GetGroupIcon()); |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 // The tooltip is the only way we have to display text explaining the error | 1734 // The tooltip is the only way we have to display text explaining the error |
| 1735 // to the user. | 1735 // to the user. |
| 1736 sync_error_button->SetTooltipText( | 1736 sync_error_button->SetTooltipText( |
| 1737 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC))); | 1737 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC))); |
| 1738 sync_error_button->SetAccessibleName( | 1738 sync_error_button->SetAccessibleName( |
| 1739 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON))); | 1739 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON))); |
| 1740 sync_error_button->SetIcon( | 1740 sync_error_button->SetIcon( |
| 1741 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); | 1741 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); |
| 1742 return sync_error_button; | 1742 return sync_error_button; |
| 1743 } | 1743 } |
| OLD | NEW |