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