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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 #include "grit/ui_resources.h" | 64 #include "grit/ui_resources.h" |
65 #include "ui/accessibility/ax_view_state.h" | 65 #include "ui/accessibility/ax_view_state.h" |
66 #include "ui/base/dragdrop/drag_utils.h" | 66 #include "ui/base/dragdrop/drag_utils.h" |
67 #include "ui/base/dragdrop/os_exchange_data.h" | 67 #include "ui/base/dragdrop/os_exchange_data.h" |
68 #include "ui/base/l10n/l10n_util.h" | 68 #include "ui/base/l10n/l10n_util.h" |
69 #include "ui/base/resource/resource_bundle.h" | 69 #include "ui/base/resource/resource_bundle.h" |
70 #include "ui/base/theme_provider.h" | 70 #include "ui/base/theme_provider.h" |
71 #include "ui/base/window_open_disposition.h" | 71 #include "ui/base/window_open_disposition.h" |
72 #include "ui/gfx/animation/slide_animation.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_constants.h" | |
74 #include "ui/gfx/text_elider.h" | 75 #include "ui/gfx/text_elider.h" |
75 #include "ui/views/button_drag_utils.h" | 76 #include "ui/views/button_drag_utils.h" |
77 #include "ui/views/controls/button/label_button.h" | |
78 #include "ui/views/controls/button/label_button_border.h" | |
76 #include "ui/views/controls/button/menu_button.h" | 79 #include "ui/views/controls/button/menu_button.h" |
77 #include "ui/views/controls/label.h" | 80 #include "ui/views/controls/label.h" |
78 #include "ui/views/drag_utils.h" | 81 #include "ui/views/drag_utils.h" |
79 #include "ui/views/metrics.h" | 82 #include "ui/views/metrics.h" |
80 #include "ui/views/view_constants.h" | 83 #include "ui/views/view_constants.h" |
81 #include "ui/views/widget/tooltip_manager.h" | 84 #include "ui/views/widget/tooltip_manager.h" |
82 #include "ui/views/widget/widget.h" | 85 #include "ui/views/widget/widget.h" |
83 #include "ui/views/window/non_client_view.h" | 86 #include "ui/views/window/non_client_view.h" |
84 | 87 |
85 using base::UserMetricsAction; | 88 using base::UserMetricsAction; |
86 using content::OpenURLParams; | 89 using content::OpenURLParams; |
87 using content::PageNavigator; | 90 using content::PageNavigator; |
88 using content::Referrer; | 91 using content::Referrer; |
89 using ui::DropTargetEvent; | 92 using ui::DropTargetEvent; |
90 using views::CustomButton; | 93 using views::CustomButton; |
94 using views::LabelButtonBorder; | |
91 using views::MenuButton; | 95 using views::MenuButton; |
92 using views::View; | 96 using views::View; |
93 | 97 |
94 // Margins around the content. | 98 // Margins around the content. |
95 static const int kDetachedTopMargin = 1; // When attached, we use 0 and let the | 99 static const int kDetachedTopMargin = 1; // When attached, we use 0 and let the |
96 // toolbar above serve as the margin. | 100 // toolbar above serve as the margin. |
97 static const int kBottomMargin = 2; | 101 static const int kBottomMargin = 2; |
98 static const int kLeftMargin = 1; | 102 static const int kLeftMargin = 1; |
99 static const int kRightMargin = 1; | 103 static const int kRightMargin = 1; |
100 | 104 |
(...skipping 27 matching lines...) Expand all Loading... | |
128 | 132 |
129 // Left-padding for the instructional text. | 133 // Left-padding for the instructional text. |
130 static const int kInstructionsPadding = 6; | 134 static const int kInstructionsPadding = 6; |
131 | 135 |
132 // Tag for the 'Other bookmarks' button. | 136 // Tag for the 'Other bookmarks' button. |
133 static const int kOtherFolderButtonTag = 1; | 137 static const int kOtherFolderButtonTag = 1; |
134 | 138 |
135 // Tag for the 'Apps Shortcut' button. | 139 // Tag for the 'Apps Shortcut' button. |
136 static const int kAppsShortcutButtonTag = 2; | 140 static const int kAppsShortcutButtonTag = 2; |
137 | 141 |
142 // Preferred padding between text and edge. | |
143 // | |
144 // Note that the vertical padding is one pixel less than it was in TextButton; | |
145 // we clip the bottom of letters like 'g' or 'p' if we don't. | |
146 static const int kButtonPaddingHorizontal = 6; | |
147 static const int kButtonPaddingVertical = 4; | |
148 | |
138 namespace { | 149 namespace { |
139 | 150 |
140 // To enable/disable BookmarkBar animations during testing. In production | 151 // To enable/disable BookmarkBar animations during testing. In production |
141 // animations are enabled by default. | 152 // animations are enabled by default. |
142 bool animations_enabled = true; | 153 bool animations_enabled = true; |
143 | 154 |
144 // BookmarkButtonBase ----------------------------------------------- | 155 // BookmarkButtonBase ----------------------------------------------- |
145 | 156 |
146 // Base class for text buttons used on the bookmark bar. | 157 // Base class for text buttons used on the bookmark bar. |
147 | 158 |
148 class BookmarkButtonBase : public views::TextButton { | 159 class BookmarkButtonBase : public views::LabelButton { |
149 public: | 160 public: |
150 BookmarkButtonBase(views::ButtonListener* listener, | 161 BookmarkButtonBase(views::ButtonListener* listener, |
151 const base::string16& title) | 162 const base::string16& title) |
152 : TextButton(listener, title) { | 163 : LabelButton(listener, title) { |
164 SetElideBehavior(gfx::FADE_TAIL); | |
153 show_animation_.reset(new gfx::SlideAnimation(this)); | 165 show_animation_.reset(new gfx::SlideAnimation(this)); |
154 if (!animations_enabled) { | 166 if (!animations_enabled) { |
155 // For some reason during testing the events generated by animating | 167 // For some reason during testing the events generated by animating |
156 // throw off the test. So, don't animate while testing. | 168 // throw off the test. So, don't animate while testing. |
157 show_animation_->Reset(1); | 169 show_animation_->Reset(1); |
158 } else { | 170 } else { |
159 show_animation_->Show(); | 171 show_animation_->Show(); |
160 } | 172 } |
161 } | 173 } |
162 | 174 |
163 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | 175 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { |
164 return e.type() == ui::ET_GESTURE_TAP || | 176 return e.type() == ui::ET_GESTURE_TAP || |
165 e.type() == ui::ET_GESTURE_TAP_DOWN || | 177 e.type() == ui::ET_GESTURE_TAP_DOWN || |
166 event_utils::IsPossibleDispositionEvent(e); | 178 event_utils::IsPossibleDispositionEvent(e); |
167 } | 179 } |
168 | 180 |
181 virtual scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const OVERRIDE { | |
182 // We change the insets on the border to match the previous TextButton. | |
183 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | |
184 border->set_insets(gfx::Insets(kButtonPaddingVertical, | |
185 kButtonPaddingHorizontal, | |
186 kButtonPaddingVertical, | |
187 kButtonPaddingHorizontal)); | |
188 return border.Pass(); | |
189 } | |
190 | |
169 private: | 191 private: |
170 scoped_ptr<gfx::SlideAnimation> show_animation_; | 192 scoped_ptr<gfx::SlideAnimation> show_animation_; |
171 | 193 |
172 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); | 194 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); |
173 }; | 195 }; |
174 | 196 |
175 // BookmarkButton ------------------------------------------------------------- | 197 // BookmarkButton ------------------------------------------------------------- |
176 | 198 |
177 // Buttons used for the bookmarks on the bookmark bar. | 199 // Buttons used for the bookmarks on the bookmark bar. |
178 | 200 |
179 class BookmarkButton : public BookmarkButtonBase { | 201 class BookmarkButton : public BookmarkButtonBase { |
180 public: | 202 public: |
181 // The internal view class name. | 203 // The internal view class name. |
182 static const char kViewClassName[]; | 204 static const char kViewClassName[]; |
183 | 205 |
184 BookmarkButton(views::ButtonListener* listener, | 206 BookmarkButton(views::ButtonListener* listener, |
185 const GURL& url, | 207 const GURL& url, |
186 const base::string16& title, | 208 const base::string16& title, |
187 Profile* profile) | 209 Profile* profile) |
188 : BookmarkButtonBase(listener, title), | 210 : BookmarkButtonBase(listener, title), |
189 url_(url), | 211 url_(url), |
190 profile_(profile) { | 212 profile_(profile) { |
191 } | 213 } |
192 | 214 |
193 virtual bool GetTooltipText(const gfx::Point& p, | 215 virtual bool GetTooltipText(const gfx::Point& p, |
194 base::string16* tooltip) const OVERRIDE { | 216 base::string16* tooltip) const OVERRIDE { |
195 gfx::Point location(p); | 217 gfx::Point location(p); |
196 ConvertPointToScreen(this, &location); | 218 ConvertPointToScreen(this, &location); |
197 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( | 219 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( |
198 GetWidget(), location, url_, text(), profile_); | 220 GetWidget(), location, url_, GetText(), profile_); |
199 return !tooltip->empty(); | 221 return !tooltip->empty(); |
200 } | 222 } |
201 | 223 |
202 virtual const char* GetClassName() const OVERRIDE { | 224 virtual const char* GetClassName() const OVERRIDE { |
203 return kViewClassName; | 225 return kViewClassName; |
204 } | 226 } |
205 | 227 |
206 private: | 228 private: |
207 const GURL& url_; | 229 const GURL& url_; |
208 Profile* profile_; | 230 Profile* profile_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 // For some reason during testing the events generated by animating | 277 // For some reason during testing the events generated by animating |
256 // throw off the test. So, don't animate while testing. | 278 // throw off the test. So, don't animate while testing. |
257 show_animation_->Reset(1); | 279 show_animation_->Reset(1); |
258 } else { | 280 } else { |
259 show_animation_->Show(); | 281 show_animation_->Show(); |
260 } | 282 } |
261 } | 283 } |
262 | 284 |
263 virtual bool GetTooltipText(const gfx::Point& p, | 285 virtual bool GetTooltipText(const gfx::Point& p, |
264 base::string16* tooltip) const OVERRIDE { | 286 base::string16* tooltip) const OVERRIDE { |
265 if (text_size_.width() > GetTextBounds().width()) | 287 if (label()->GetPreferredSize().width() > label()->size().width()) |
266 *tooltip = text_; | 288 *tooltip = GetText(); |
267 return !tooltip->empty(); | 289 return !tooltip->empty(); |
268 } | 290 } |
269 | 291 |
270 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | 292 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { |
271 // Left clicks and taps should show the menu contents and right clicks | 293 // Left clicks and taps should show the menu contents and right clicks |
272 // should show the context menu. They should not trigger the opening of | 294 // should show the context menu. They should not trigger the opening of |
273 // underlying urls. | 295 // underlying urls. |
274 if (e.type() == ui::ET_GESTURE_TAP || | 296 if (e.type() == ui::ET_GESTURE_TAP || |
275 (e.IsMouseEvent() && (e.flags() & | 297 (e.IsMouseEvent() && (e.flags() & |
276 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) | 298 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) |
277 return false; | 299 return false; |
278 | 300 |
279 if (e.IsMouseEvent()) | 301 if (e.IsMouseEvent()) |
280 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; | 302 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; |
281 return false; | 303 return false; |
282 } | 304 } |
283 | 305 |
284 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
285 views::MenuButton::PaintButton(canvas, views::MenuButton::PB_NORMAL); | |
286 } | |
287 | |
288 private: | 306 private: |
289 scoped_ptr<gfx::SlideAnimation> show_animation_; | 307 scoped_ptr<gfx::SlideAnimation> show_animation_; |
290 | 308 |
291 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 309 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
292 }; | 310 }; |
293 | 311 |
294 // OverFlowButton (chevron) -------------------------------------------------- | 312 // OverFlowButton (chevron) -------------------------------------------------- |
295 | 313 |
296 class OverFlowButton : public views::MenuButton { | 314 class OverFlowButton : public views::MenuButton { |
297 public: | 315 public: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); | 428 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); |
411 }; | 429 }; |
412 | 430 |
413 // BookmarkBarView ------------------------------------------------------------ | 431 // BookmarkBarView ------------------------------------------------------------ |
414 | 432 |
415 // static | 433 // static |
416 const int BookmarkBarView::kMaxButtonWidth = 150; | 434 const int BookmarkBarView::kMaxButtonWidth = 150; |
417 const int BookmarkBarView::kNewtabHorizontalPadding = 2; | 435 const int BookmarkBarView::kNewtabHorizontalPadding = 2; |
418 const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3; | 436 const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3; |
419 | 437 |
420 static const gfx::ImageSkia& GetDefaultFavicon() { | 438 const gfx::ImageSkia& GetDefaultFavicon() { |
421 if (!kDefaultFavicon) { | 439 if (!kDefaultFavicon) { |
422 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 440 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
423 kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON); | 441 kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON); |
424 } | 442 } |
425 return *kDefaultFavicon; | 443 return *kDefaultFavicon; |
426 } | 444 } |
427 | 445 |
428 static const gfx::ImageSkia& GetFolderIcon() { | 446 const gfx::ImageSkia& GetFolderIcon() { |
429 if (!kFolderIcon) { | 447 if (!kFolderIcon) { |
430 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 448 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
431 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); | 449 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); |
432 } | 450 } |
433 return *kFolderIcon; | 451 return *kFolderIcon; |
434 } | 452 } |
435 | 453 |
436 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) | 454 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
437 : page_navigator_(NULL), | 455 : page_navigator_(NULL), |
438 model_(NULL), | 456 model_(NULL), |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1085 Layout(); | 1103 Layout(); |
1086 SchedulePaint(); | 1104 SchedulePaint(); |
1087 } | 1105 } |
1088 | 1106 |
1089 void BookmarkBarView::BookmarkNodeFaviconChanged(BookmarkModel* model, | 1107 void BookmarkBarView::BookmarkNodeFaviconChanged(BookmarkModel* model, |
1090 const BookmarkNode* node) { | 1108 const BookmarkNode* node) { |
1091 BookmarkNodeChangedImpl(model, node); | 1109 BookmarkNodeChangedImpl(model, node); |
1092 } | 1110 } |
1093 | 1111 |
1094 void BookmarkBarView::WriteDragDataForView(View* sender, | 1112 void BookmarkBarView::WriteDragDataForView(View* sender, |
1095 const gfx::Point& press_pt, | 1113 const gfx::Point& press_pt, |
sky
2014/06/09 15:42:00
I think you're missing the offset (press_pt) used
Elliot Glaysher
2014/06/11 00:27:28
Added optional offset parameter to SetURLAndDragIm
| |
1096 ui::OSExchangeData* data) { | 1114 ui::OSExchangeData* data) { |
1097 content::RecordAction(UserMetricsAction("BookmarkBar_DragButton")); | 1115 content::RecordAction(UserMetricsAction("BookmarkBar_DragButton")); |
1098 | 1116 |
1099 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1117 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
1100 if (sender == GetBookmarkButton(i)) { | 1118 if (sender == GetBookmarkButton(i)) { |
1101 views::TextButton* button = GetBookmarkButton(i); | 1119 views::LabelButton* button = GetBookmarkButton(i); |
1102 scoped_ptr<gfx::Canvas> canvas( | 1120 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); |
1103 views::GetCanvasForDragImage(button->GetWidget(), button->size())); | 1121 |
1104 button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); | 1122 const gfx::ImageSkia& icon = *model_->GetFavicon(node).ToImageSkia(); |
1105 drag_utils::SetDragImageOnDataObject(*canvas, button->size(), | 1123 button_drag_utils::SetURLAndDragImage( |
1106 press_pt.OffsetFromOrigin(), | 1124 node->url(), |
1107 data); | 1125 node->GetTitle(), |
1126 icon, | |
1127 data, | |
1128 button->GetWidget()); | |
1108 WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data); | 1129 WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data); |
1109 return; | 1130 return; |
1110 } | 1131 } |
1111 } | 1132 } |
1112 NOTREACHED(); | 1133 NOTREACHED(); |
1113 } | 1134 } |
1114 | 1135 |
1115 int BookmarkBarView::GetDragOperationsForView(View* sender, | 1136 int BookmarkBarView::GetDragOperationsForView(View* sender, |
1116 const gfx::Point& p) { | 1137 const gfx::Point& p) { |
1117 if (size_animation_->is_animating() || | 1138 if (size_animation_->is_animating() || |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 // done loading, then we'll populate the bar. | 1330 // done loading, then we'll populate the bar. |
1310 } | 1331 } |
1311 } | 1332 } |
1312 | 1333 |
1313 int BookmarkBarView::GetBookmarkButtonCount() const { | 1334 int BookmarkBarView::GetBookmarkButtonCount() const { |
1314 // We contain four non-bookmark button views: other bookmarks, bookmarks | 1335 // We contain four non-bookmark button views: other bookmarks, bookmarks |
1315 // separator, chevrons (for overflow), apps page, and the instruction label. | 1336 // separator, chevrons (for overflow), apps page, and the instruction label. |
1316 return child_count() - 5; | 1337 return child_count() - 5; |
1317 } | 1338 } |
1318 | 1339 |
1319 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { | 1340 views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) { |
1320 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1341 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
1321 return static_cast<views::TextButton*>(child_at(index)); | 1342 return static_cast<views::LabelButton*>(child_at(index)); |
1322 } | 1343 } |
1323 | 1344 |
1324 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { | 1345 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { |
1325 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : | 1346 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : |
1326 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; | 1347 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; |
1327 } | 1348 } |
1328 | 1349 |
1329 int BookmarkBarView::GetFirstHiddenNodeIndex() { | 1350 int BookmarkBarView::GetFirstHiddenNodeIndex() { |
1330 const int bb_count = GetBookmarkButtonCount(); | 1351 const int bb_count = GetBookmarkButtonCount(); |
1331 for (int i = 0; i < bb_count; ++i) { | 1352 for (int i = 0; i < bb_count; ++i) { |
1332 if (!GetBookmarkButton(i)->visible()) | 1353 if (!GetBookmarkButton(i)->visible()) |
1333 return i; | 1354 return i; |
1334 } | 1355 } |
1335 return bb_count; | 1356 return bb_count; |
1336 } | 1357 } |
1337 | 1358 |
1338 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { | 1359 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { |
1339 // Title is set in Loaded. | 1360 // Title is set in Loaded. |
1340 MenuButton* button = | 1361 MenuButton* button = |
1341 new BookmarkFolderButton(this, base::string16(), this, false); | 1362 new BookmarkFolderButton(this, base::string16(), this, false); |
1342 button->set_id(VIEW_ID_OTHER_BOOKMARKS); | 1363 button->set_id(VIEW_ID_OTHER_BOOKMARKS); |
1343 button->SetIcon(GetFolderIcon()); | 1364 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon()); |
1344 button->set_context_menu_controller(this); | 1365 button->set_context_menu_controller(this); |
1345 button->set_tag(kOtherFolderButtonTag); | 1366 button->set_tag(kOtherFolderButtonTag); |
1346 return button; | 1367 return button; |
1347 } | 1368 } |
1348 | 1369 |
1349 MenuButton* BookmarkBarView::CreateOverflowButton() { | 1370 MenuButton* BookmarkBarView::CreateOverflowButton() { |
1350 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1371 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
1351 MenuButton* button = new OverFlowButton(this); | 1372 MenuButton* button = new OverFlowButton(this); |
1352 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); | 1373 button->SetImage(views::Button::STATE_NORMAL, |
1374 *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); | |
1353 | 1375 |
1354 // The overflow button's image contains an arrow and therefore it is a | 1376 // The overflow button's image contains an arrow and therefore it is a |
1355 // direction sensitive image and we need to flip it if the UI layout is | 1377 // direction sensitive image and we need to flip it if the UI layout is |
1356 // right-to-left. | 1378 // right-to-left. |
1357 // | 1379 // |
1358 // By default, menu buttons are not flipped because they generally contain | 1380 // By default, menu buttons are not flipped because they generally contain |
1359 // text and flipping the gfx::Canvas object will break text rendering. Since | 1381 // text and flipping the gfx::Canvas object will break text rendering. Since |
1360 // the overflow button does not contain text, we can safely flip it. | 1382 // the overflow button does not contain text, we can safely flip it. |
1361 button->EnableCanvasFlippingForRTLUI(true); | 1383 button->EnableCanvasFlippingForRTLUI(true); |
1362 | 1384 |
1363 // Make visible as necessary. | 1385 // Make visible as necessary. |
1364 button->SetVisible(false); | 1386 button->SetVisible(false); |
1365 // Set accessibility name. | 1387 // Set accessibility name. |
1366 button->SetAccessibleName( | 1388 button->SetAccessibleName( |
1367 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON)); | 1389 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON)); |
1368 return button; | 1390 return button; |
1369 } | 1391 } |
1370 | 1392 |
1371 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { | 1393 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { |
1372 if (node->is_url()) { | 1394 if (node->is_url()) { |
1373 BookmarkButton* button = new BookmarkButton( | 1395 BookmarkButton* button = new BookmarkButton( |
1374 this, node->url(), node->GetTitle(), browser_->profile()); | 1396 this, node->url(), node->GetTitle(), browser_->profile()); |
1375 ConfigureButton(node, button); | 1397 ConfigureButton(node, button); |
1376 return button; | 1398 return button; |
1377 } else { | 1399 } else { |
1378 views::MenuButton* button = new BookmarkFolderButton( | 1400 views::MenuButton* button = new BookmarkFolderButton( |
1379 this, node->GetTitle(), this, false); | 1401 this, node->GetTitle(), this, false); |
1380 button->SetIcon(GetFolderIcon()); | 1402 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon()); |
1381 ConfigureButton(node, button); | 1403 ConfigureButton(node, button); |
1382 return button; | 1404 return button; |
1383 } | 1405 } |
1384 } | 1406 } |
1385 | 1407 |
1386 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { | 1408 views::LabelButton* BookmarkBarView::CreateAppsPageShortcutButton() { |
1387 views::TextButton* button = new ShortcutButton( | 1409 views::LabelButton* button = new ShortcutButton( |
1388 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); | 1410 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); |
1389 button->SetTooltipText(l10n_util::GetStringUTF16( | 1411 button->SetTooltipText(l10n_util::GetStringUTF16( |
1390 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); | 1412 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); |
1391 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); | 1413 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
1392 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1414 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
1393 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT)); | 1415 button->SetImage(views::Button::STATE_NORMAL, |
1416 *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT)); | |
1394 button->set_context_menu_controller(this); | 1417 button->set_context_menu_controller(this); |
1395 button->set_tag(kAppsShortcutButtonTag); | 1418 button->set_tag(kAppsShortcutButtonTag); |
1396 return button; | 1419 return button; |
1397 } | 1420 } |
1398 | 1421 |
1399 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, | 1422 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
1400 views::TextButton* button) { | 1423 views::LabelButton* button) { |
1401 button->SetText(node->GetTitle()); | 1424 button->SetText(node->GetTitle()); |
1402 button->SetAccessibleName(node->GetTitle()); | 1425 button->SetAccessibleName(node->GetTitle()); |
1403 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); | 1426 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
1404 // We don't always have a theme provider (ui tests, for example). | 1427 // We don't always have a theme provider (ui tests, for example). |
1405 if (GetThemeProvider()) { | 1428 if (GetThemeProvider()) { |
1406 button->SetEnabledColor(GetThemeProvider()->GetColor( | 1429 button->SetTextColor( |
1407 ThemeProperties::COLOR_BOOKMARK_TEXT)); | 1430 views::Button::STATE_NORMAL, |
1431 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | |
1408 } | 1432 } |
1409 | 1433 |
1410 button->ClearMaxTextSize(); | |
msw
2014/06/09 17:18:40
ditto: call set_min_size(gfx::Size())
| |
1411 button->set_context_menu_controller(this); | 1434 button->set_context_menu_controller(this); |
1412 button->set_drag_controller(this); | 1435 button->set_drag_controller(this); |
1413 if (node->is_url()) { | 1436 if (node->is_url()) { |
1414 const gfx::Image& favicon = model_->GetFavicon(node); | 1437 const gfx::Image& favicon = model_->GetFavicon(node); |
1415 if (!favicon.IsEmpty()) | 1438 if (!favicon.IsEmpty()) |
1416 button->SetIcon(*favicon.ToImageSkia()); | 1439 button->SetImage(views::Button::STATE_NORMAL, *favicon.ToImageSkia()); |
1417 else | 1440 else |
1418 button->SetIcon(GetDefaultFavicon()); | 1441 button->SetImage(views::Button::STATE_NORMAL, GetDefaultFavicon()); |
1419 } | 1442 } |
1420 button->set_max_width(kMaxButtonWidth); | 1443 button->set_max_size(gfx::Size(kMaxButtonWidth, 0)); |
1421 } | 1444 } |
1422 | 1445 |
1423 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, | 1446 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, |
1424 const BookmarkNode* parent, | 1447 const BookmarkNode* parent, |
1425 int index) { | 1448 int index) { |
1426 UpdateOtherBookmarksVisibility(); | 1449 UpdateOtherBookmarksVisibility(); |
1427 if (parent != model_->bookmark_bar_node()) { | 1450 if (parent != model_->bookmark_bar_node()) { |
1428 // We only care about nodes on the bookmark bar. | 1451 // We only care about nodes on the bookmark bar. |
1429 return; | 1452 return; |
1430 } | 1453 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 } | 1485 } |
1463 | 1486 |
1464 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, | 1487 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
1465 const BookmarkNode* node) { | 1488 const BookmarkNode* node) { |
1466 if (node->parent() != model_->bookmark_bar_node()) { | 1489 if (node->parent() != model_->bookmark_bar_node()) { |
1467 // We only care about nodes on the bookmark bar. | 1490 // We only care about nodes on the bookmark bar. |
1468 return; | 1491 return; |
1469 } | 1492 } |
1470 int index = model_->bookmark_bar_node()->GetIndexOf(node); | 1493 int index = model_->bookmark_bar_node()->GetIndexOf(node); |
1471 DCHECK_NE(-1, index); | 1494 DCHECK_NE(-1, index); |
1472 views::TextButton* button = GetBookmarkButton(index); | 1495 views::LabelButton* button = GetBookmarkButton(index); |
1473 gfx::Size old_pref = button->GetPreferredSize(); | 1496 gfx::Size old_pref = button->GetPreferredSize(); |
1474 ConfigureButton(node, button); | 1497 ConfigureButton(node, button); |
1475 gfx::Size new_pref = button->GetPreferredSize(); | 1498 gfx::Size new_pref = button->GetPreferredSize(); |
1476 if (old_pref.width() != new_pref.width()) { | 1499 if (old_pref.width() != new_pref.width()) { |
1477 Layout(); | 1500 Layout(); |
1478 SchedulePaint(); | 1501 SchedulePaint(); |
1479 } else if (button->visible()) { | 1502 } else if (button->visible()) { |
1480 button->SchedulePaint(); | 1503 button->SchedulePaint(); |
1481 } | 1504 } |
1482 } | 1505 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1556 int ops = data.GetFirstNode(model_, profile->GetPath()) ? | 1579 int ops = data.GetFirstNode(model_, profile->GetPath()) ? |
1557 ui::DragDropTypes::DRAG_MOVE : | 1580 ui::DragDropTypes::DRAG_MOVE : |
1558 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | 1581 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; |
1559 location->operation = chrome::GetPreferredBookmarkDropOperation( | 1582 location->operation = chrome::GetPreferredBookmarkDropOperation( |
1560 event.source_operations(), ops); | 1583 event.source_operations(), ops); |
1561 return; | 1584 return; |
1562 } | 1585 } |
1563 | 1586 |
1564 for (int i = 0; i < GetBookmarkButtonCount() && | 1587 for (int i = 0; i < GetBookmarkButtonCount() && |
1565 GetBookmarkButton(i)->visible() && !found; i++) { | 1588 GetBookmarkButton(i)->visible() && !found; i++) { |
1566 views::TextButton* button = GetBookmarkButton(i); | 1589 views::LabelButton* button = GetBookmarkButton(i); |
1567 int button_x = mirrored_x - button->x(); | 1590 int button_x = mirrored_x - button->x(); |
1568 int button_w = button->width(); | 1591 int button_w = button->width(); |
1569 if (button_x < button_w) { | 1592 if (button_x < button_w) { |
1570 found = true; | 1593 found = true; |
1571 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); | 1594 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); |
1572 if (node->is_folder()) { | 1595 if (node->is_folder()) { |
1573 if (button_x <= views::kDropBetweenPixels) { | 1596 if (button_x <= views::kDropBetweenPixels) { |
1574 location->index = i; | 1597 location->index = i; |
1575 } else if (button_x < button_w - views::kDropBetweenPixels) { | 1598 } else if (button_x < button_w - views::kDropBetweenPixels) { |
1576 location->index = i; | 1599 location->index = i; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1693 return other_bookmarked_button_; | 1716 return other_bookmarked_button_; |
1694 } | 1717 } |
1695 | 1718 |
1696 void BookmarkBarView::UpdateColors() { | 1719 void BookmarkBarView::UpdateColors() { |
1697 // We don't always have a theme provider (ui tests, for example). | 1720 // We don't always have a theme provider (ui tests, for example). |
1698 const ui::ThemeProvider* theme_provider = GetThemeProvider(); | 1721 const ui::ThemeProvider* theme_provider = GetThemeProvider(); |
1699 if (!theme_provider) | 1722 if (!theme_provider) |
1700 return; | 1723 return; |
1701 SkColor text_color = | 1724 SkColor text_color = |
1702 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 1725 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
1703 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1726 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
1704 GetBookmarkButton(i)->SetEnabledColor(text_color); | 1727 GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, |
1705 other_bookmarked_button()->SetEnabledColor(text_color); | 1728 text_color); |
1729 } | |
1730 other_bookmarked_button()->SetTextColor(views::Button::STATE_NORMAL, | |
1731 text_color); | |
1706 if (apps_page_shortcut_->visible()) | 1732 if (apps_page_shortcut_->visible()) |
1707 apps_page_shortcut_->SetEnabledColor(text_color); | 1733 apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, text_color); |
1708 } | 1734 } |
1709 | 1735 |
1710 void BookmarkBarView::UpdateOtherBookmarksVisibility() { | 1736 void BookmarkBarView::UpdateOtherBookmarksVisibility() { |
1711 bool has_other_children = !model_->other_node()->empty(); | 1737 bool has_other_children = !model_->other_node()->empty(); |
1712 if (has_other_children == other_bookmarked_button_->visible()) | 1738 if (has_other_children == other_bookmarked_button_->visible()) |
1713 return; | 1739 return; |
1714 other_bookmarked_button_->SetVisible(has_other_children); | 1740 other_bookmarked_button_->SetVisible(has_other_children); |
1715 UpdateBookmarksSeparatorVisibility(); | 1741 UpdateBookmarksSeparatorVisibility(); |
1716 Layout(); | 1742 Layout(); |
1717 SchedulePaint(); | 1743 SchedulePaint(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1829 DCHECK(apps_page_shortcut_); | 1855 DCHECK(apps_page_shortcut_); |
1830 // Only perform layout if required. | 1856 // Only perform layout if required. |
1831 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 1857 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
1832 browser_->profile(), browser_->host_desktop_type()); | 1858 browser_->profile(), browser_->host_desktop_type()); |
1833 if (apps_page_shortcut_->visible() == visible) | 1859 if (apps_page_shortcut_->visible() == visible) |
1834 return; | 1860 return; |
1835 apps_page_shortcut_->SetVisible(visible); | 1861 apps_page_shortcut_->SetVisible(visible); |
1836 UpdateBookmarksSeparatorVisibility(); | 1862 UpdateBookmarksSeparatorVisibility(); |
1837 Layout(); | 1863 Layout(); |
1838 } | 1864 } |
OLD | NEW |