Chromium Code Reviews| 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) 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 int max_width = tooltip_manager->GetMaxWidth(location); |
|
sky
2016/11/17 01:08:28
Please add a comment as to why this is being done.
oshima
2016/11/17 14:02:32
Done.
| |
| 268 GetWidget(), location, url_, GetText()); | 271 if (!tooltip_.size() || max_width != max_width_) { |
|
sky
2016/11/17 01:08:28
!size() -> empty()
oshima
2016/11/17 14:02:33
Done.
| |
| 272 max_width_ = max_width; | |
| 273 tooltip_ = BookmarkBarView::CreateToolTipForURLAndTitle( | |
| 274 max_width_, tooltip_manager->GetFontList(), url_, GetText()); | |
| 275 } | |
| 276 *tooltip = tooltip_; | |
| 269 return !tooltip->empty(); | 277 return !tooltip->empty(); |
| 270 } | 278 } |
| 271 | 279 |
| 280 void SetText(const base::string16& text) override { | |
| 281 BookmarkButtonBase::SetText(text); | |
| 282 tooltip_.empty(); | |
| 283 } | |
| 284 | |
| 272 const char* GetClassName() const override { return kViewClassName; } | 285 const char* GetClassName() const override { return kViewClassName; } |
| 273 | 286 |
| 274 private: | 287 private: |
| 288 mutable int max_width_ = 0; | |
|
sky
2016/11/17 01:08:28
max_width_ by itself isn't clear, especially with
oshima
2016/11/17 14:02:33
Done.
| |
| 289 mutable base::string16 tooltip_; | |
| 275 const GURL& url_; | 290 const GURL& url_; |
| 276 | 291 |
| 277 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 292 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
| 278 }; | 293 }; |
| 279 | 294 |
| 280 // static | 295 // static |
| 281 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; | 296 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; |
| 282 | 297 |
| 283 // ShortcutButton ------------------------------------------------------------- | 298 // ShortcutButton ------------------------------------------------------------- |
| 284 | 299 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 if (!throbbing_view_) | 722 if (!throbbing_view_) |
| 708 return; | 723 return; |
| 709 | 724 |
| 710 // If not immediate, cycle through 2 more complete cycles. | 725 // If not immediate, cycle through 2 more complete cycles. |
| 711 throbbing_view_->StartThrobbing(immediate ? 0 : 4); | 726 throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
| 712 throbbing_view_ = nullptr; | 727 throbbing_view_ = nullptr; |
| 713 } | 728 } |
| 714 | 729 |
| 715 // static | 730 // static |
| 716 base::string16 BookmarkBarView::CreateToolTipForURLAndTitle( | 731 base::string16 BookmarkBarView::CreateToolTipForURLAndTitle( |
| 717 const views::Widget* widget, | 732 int max_width, |
| 718 const gfx::Point& screen_loc, | 733 const gfx::FontList& tt_fonts, |
| 719 const GURL& url, | 734 const GURL& url, |
| 720 const base::string16& title) { | 735 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; | 736 base::string16 result; |
| 725 | 737 |
| 726 // First the title. | 738 // First the title. |
| 727 if (!title.empty()) { | 739 if (!title.empty()) { |
| 728 base::string16 localized_title = title; | 740 base::string16 localized_title = title; |
| 729 base::i18n::AdjustStringForLocaleDirection(&localized_title); | 741 base::i18n::AdjustStringForLocaleDirection(&localized_title); |
| 730 result.append(gfx::ElideText(localized_title, tt_fonts, max_width, | 742 result.append(gfx::ElideText(localized_title, tt_fonts, max_width, |
| 731 gfx::ELIDE_TAIL)); | 743 gfx::ELIDE_TAIL)); |
| 732 } | 744 } |
| 733 | 745 |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2119 return; | 2131 return; |
| 2120 apps_page_shortcut_->SetVisible(visible); | 2132 apps_page_shortcut_->SetVisible(visible); |
| 2121 UpdateBookmarksSeparatorVisibility(); | 2133 UpdateBookmarksSeparatorVisibility(); |
| 2122 LayoutAndPaint(); | 2134 LayoutAndPaint(); |
| 2123 } | 2135 } |
| 2124 | 2136 |
| 2125 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2137 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
| 2126 if (UpdateOtherAndManagedButtonsVisibility()) | 2138 if (UpdateOtherAndManagedButtonsVisibility()) |
| 2127 LayoutAndPaint(); | 2139 LayoutAndPaint(); |
| 2128 } | 2140 } |
| OLD | NEW |