| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 class BookmarkButton : public BookmarkButtonBase { | 250 class BookmarkButton : public BookmarkButtonBase { |
| 251 public: | 251 public: |
| 252 // The internal view class name. | 252 // The internal view class name. |
| 253 static const char kViewClassName[]; | 253 static const char kViewClassName[]; |
| 254 | 254 |
| 255 BookmarkButton(views::ButtonListener* listener, | 255 BookmarkButton(views::ButtonListener* listener, |
| 256 const GURL& url, | 256 const GURL& url, |
| 257 const base::string16& title) | 257 const base::string16& title) |
| 258 : BookmarkButtonBase(listener, title), url_(url) {} | 258 : BookmarkButtonBase(listener, title), url_(url) {} |
| 259 | 259 |
| 260 // views::View: |
| 260 bool GetTooltipText(const gfx::Point& p, | 261 bool GetTooltipText(const gfx::Point& p, |
| 261 base::string16* tooltip) const override { | 262 base::string16* tooltip_text) const override { |
| 263 const views::TooltipManager* tooltip_manager = |
| 264 GetWidget()->GetTooltipManager(); |
| 262 gfx::Point location(p); | 265 gfx::Point location(p); |
| 263 ConvertPointToScreen(this, &location); | 266 ConvertPointToScreen(this, &location); |
| 264 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( | 267 // Also update when the maximum width for tooltip has changed because the |
| 265 GetWidget(), location, url_, GetText()); | 268 // it may be elided differently. |
| 266 return !tooltip->empty(); | 269 int max_tooltip_width = tooltip_manager->GetMaxWidth(location); |
| 270 if (tooltip_text_.empty() || max_tooltip_width != max_tooltip_width_) { |
| 271 max_tooltip_width_ = max_tooltip_width; |
| 272 tooltip_text_ = BookmarkBarView::CreateToolTipForURLAndTitle( |
| 273 max_tooltip_width_, tooltip_manager->GetFontList(), url_, GetText()); |
| 274 } |
| 275 *tooltip_text = tooltip_text_; |
| 276 return !tooltip_text->empty(); |
| 277 } |
| 278 |
| 279 void SetText(const base::string16& text) override { |
| 280 BookmarkButtonBase::SetText(text); |
| 281 tooltip_text_.empty(); |
| 267 } | 282 } |
| 268 | 283 |
| 269 const char* GetClassName() const override { return kViewClassName; } | 284 const char* GetClassName() const override { return kViewClassName; } |
| 270 | 285 |
| 271 private: | 286 private: |
| 287 // A cached value of maximum width for tooltip to skip generating |
| 288 // new tooltip text. |
| 289 mutable int max_tooltip_width_ = 0; |
| 290 mutable base::string16 tooltip_text_; |
| 272 const GURL& url_; | 291 const GURL& url_; |
| 273 | 292 |
| 274 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 293 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
| 275 }; | 294 }; |
| 276 | 295 |
| 277 // static | 296 // static |
| 278 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; | 297 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; |
| 279 | 298 |
| 280 // ShortcutButton ------------------------------------------------------------- | 299 // ShortcutButton ------------------------------------------------------------- |
| 281 | 300 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 if (!throbbing_view_) | 721 if (!throbbing_view_) |
| 703 return; | 722 return; |
| 704 | 723 |
| 705 // If not immediate, cycle through 2 more complete cycles. | 724 // If not immediate, cycle through 2 more complete cycles. |
| 706 throbbing_view_->StartThrobbing(immediate ? 0 : 4); | 725 throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
| 707 throbbing_view_ = nullptr; | 726 throbbing_view_ = nullptr; |
| 708 } | 727 } |
| 709 | 728 |
| 710 // static | 729 // static |
| 711 base::string16 BookmarkBarView::CreateToolTipForURLAndTitle( | 730 base::string16 BookmarkBarView::CreateToolTipForURLAndTitle( |
| 712 const views::Widget* widget, | 731 int max_width, |
| 713 const gfx::Point& screen_loc, | 732 const gfx::FontList& tt_fonts, |
| 714 const GURL& url, | 733 const GURL& url, |
| 715 const base::string16& title) { | 734 const base::string16& title) { |
| 716 const views::TooltipManager* tooltip_manager = widget->GetTooltipManager(); | |
| 717 int max_width = tooltip_manager->GetMaxWidth(screen_loc); | |
| 718 const gfx::FontList tt_fonts = tooltip_manager->GetFontList(); | |
| 719 base::string16 result; | 735 base::string16 result; |
| 720 | 736 |
| 721 // First the title. | 737 // First the title. |
| 722 if (!title.empty()) { | 738 if (!title.empty()) { |
| 723 base::string16 localized_title = title; | 739 base::string16 localized_title = title; |
| 724 base::i18n::AdjustStringForLocaleDirection(&localized_title); | 740 base::i18n::AdjustStringForLocaleDirection(&localized_title); |
| 725 result.append(gfx::ElideText(localized_title, tt_fonts, max_width, | 741 result.append(gfx::ElideText(localized_title, tt_fonts, max_width, |
| 726 gfx::ELIDE_TAIL)); | 742 gfx::ELIDE_TAIL)); |
| 727 } | 743 } |
| 728 | 744 |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2114 return; | 2130 return; |
| 2115 apps_page_shortcut_->SetVisible(visible); | 2131 apps_page_shortcut_->SetVisible(visible); |
| 2116 UpdateBookmarksSeparatorVisibility(); | 2132 UpdateBookmarksSeparatorVisibility(); |
| 2117 LayoutAndPaint(); | 2133 LayoutAndPaint(); |
| 2118 } | 2134 } |
| 2119 | 2135 |
| 2120 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2136 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
| 2121 if (UpdateOtherAndManagedButtonsVisibility()) | 2137 if (UpdateOtherAndManagedButtonsVisibility()) |
| 2122 LayoutAndPaint(); | 2138 LayoutAndPaint(); |
| 2123 } | 2139 } |
| OLD | NEW |