Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

Issue 298813002: views: Move MenuButton from TextButton to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try fixing linux compile wrt NewAvatarButton. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 // Tag for the 'Managed bookmarks' button. 149 // Tag for the 'Managed bookmarks' button.
139 static const int kManagedFolderButtonTag = 3; 150 static const int kManagedFolderButtonTag = 3;
140 151
141 namespace { 152 namespace {
142 153
143 // To enable/disable BookmarkBar animations during testing. In production 154 // To enable/disable BookmarkBar animations during testing. In production
144 // animations are enabled by default. 155 // animations are enabled by default.
145 bool animations_enabled = true; 156 bool animations_enabled = true;
146 157
147 // BookmarkButtonBase ----------------------------------------------- 158 // BookmarkButtonBase -----------------------------------------------
148 159
149 // Base class for text buttons used on the bookmark bar. 160 // Base class for text buttons used on the bookmark bar.
150 161
151 class BookmarkButtonBase : public views::TextButton { 162 class BookmarkButtonBase : public views::LabelButton {
152 public: 163 public:
153 BookmarkButtonBase(views::ButtonListener* listener, 164 BookmarkButtonBase(views::ButtonListener* listener,
154 const base::string16& title) 165 const base::string16& title)
155 : TextButton(listener, title) { 166 : LabelButton(listener, title) {
167 SetElideBehavior(gfx::FADE_TAIL);
msw 2014/06/11 00:55:46 This changed the appearance of elided bookmark but
156 show_animation_.reset(new gfx::SlideAnimation(this)); 168 show_animation_.reset(new gfx::SlideAnimation(this));
157 if (!animations_enabled) { 169 if (!animations_enabled) {
158 // For some reason during testing the events generated by animating 170 // For some reason during testing the events generated by animating
159 // throw off the test. So, don't animate while testing. 171 // throw off the test. So, don't animate while testing.
160 show_animation_->Reset(1); 172 show_animation_->Reset(1);
161 } else { 173 } else {
162 show_animation_->Show(); 174 show_animation_->Show();
163 } 175 }
164 } 176 }
165 177
166 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { 178 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE {
167 return e.type() == ui::ET_GESTURE_TAP || 179 return e.type() == ui::ET_GESTURE_TAP ||
168 e.type() == ui::ET_GESTURE_TAP_DOWN || 180 e.type() == ui::ET_GESTURE_TAP_DOWN ||
169 event_utils::IsPossibleDispositionEvent(e); 181 event_utils::IsPossibleDispositionEvent(e);
170 } 182 }
171 183
184 virtual scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const OVERRIDE {
185 // We change the insets on the border to match the previous TextButton.
186 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder();
187 border->set_insets(gfx::Insets(kButtonPaddingVertical,
188 kButtonPaddingHorizontal,
189 kButtonPaddingVertical,
190 kButtonPaddingHorizontal));
191 return border.Pass();
192 }
193
172 private: 194 private:
173 scoped_ptr<gfx::SlideAnimation> show_animation_; 195 scoped_ptr<gfx::SlideAnimation> show_animation_;
174 196
175 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); 197 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase);
176 }; 198 };
177 199
178 // BookmarkButton ------------------------------------------------------------- 200 // BookmarkButton -------------------------------------------------------------
179 201
180 // Buttons used for the bookmarks on the bookmark bar. 202 // Buttons used for the bookmarks on the bookmark bar.
181 203
182 class BookmarkButton : public BookmarkButtonBase { 204 class BookmarkButton : public BookmarkButtonBase {
183 public: 205 public:
184 // The internal view class name. 206 // The internal view class name.
185 static const char kViewClassName[]; 207 static const char kViewClassName[];
186 208
187 BookmarkButton(views::ButtonListener* listener, 209 BookmarkButton(views::ButtonListener* listener,
188 const GURL& url, 210 const GURL& url,
189 const base::string16& title, 211 const base::string16& title,
190 Profile* profile) 212 Profile* profile)
191 : BookmarkButtonBase(listener, title), 213 : BookmarkButtonBase(listener, title),
192 url_(url), 214 url_(url),
193 profile_(profile) { 215 profile_(profile) {
194 } 216 }
195 217
196 virtual bool GetTooltipText(const gfx::Point& p, 218 virtual bool GetTooltipText(const gfx::Point& p,
197 base::string16* tooltip) const OVERRIDE { 219 base::string16* tooltip) const OVERRIDE {
198 gfx::Point location(p); 220 gfx::Point location(p);
199 ConvertPointToScreen(this, &location); 221 ConvertPointToScreen(this, &location);
200 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( 222 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle(
201 GetWidget(), location, url_, text(), profile_); 223 GetWidget(), location, url_, GetText(), profile_);
202 return !tooltip->empty(); 224 return !tooltip->empty();
203 } 225 }
204 226
205 virtual const char* GetClassName() const OVERRIDE { 227 virtual const char* GetClassName() const OVERRIDE {
206 return kViewClassName; 228 return kViewClassName;
207 } 229 }
208 230
209 private: 231 private:
210 const GURL& url_; 232 const GURL& url_;
211 Profile* profile_; 233 Profile* profile_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // For some reason during testing the events generated by animating 280 // For some reason during testing the events generated by animating
259 // throw off the test. So, don't animate while testing. 281 // throw off the test. So, don't animate while testing.
260 show_animation_->Reset(1); 282 show_animation_->Reset(1);
261 } else { 283 } else {
262 show_animation_->Show(); 284 show_animation_->Show();
263 } 285 }
264 } 286 }
265 287
266 virtual bool GetTooltipText(const gfx::Point& p, 288 virtual bool GetTooltipText(const gfx::Point& p,
267 base::string16* tooltip) const OVERRIDE { 289 base::string16* tooltip) const OVERRIDE {
268 if (text_size_.width() > GetTextBounds().width()) 290 if (label()->GetPreferredSize().width() > label()->size().width())
269 *tooltip = text_; 291 *tooltip = GetText();
270 return !tooltip->empty(); 292 return !tooltip->empty();
271 } 293 }
272 294
273 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { 295 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE {
274 // Left clicks and taps should show the menu contents and right clicks 296 // Left clicks and taps should show the menu contents and right clicks
275 // should show the context menu. They should not trigger the opening of 297 // should show the context menu. They should not trigger the opening of
276 // underlying urls. 298 // underlying urls.
277 if (e.type() == ui::ET_GESTURE_TAP || 299 if (e.type() == ui::ET_GESTURE_TAP ||
278 (e.IsMouseEvent() && (e.flags() & 300 (e.IsMouseEvent() && (e.flags() &
279 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) 301 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON))))
280 return false; 302 return false;
281 303
282 if (e.IsMouseEvent()) 304 if (e.IsMouseEvent())
283 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; 305 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB;
284 return false; 306 return false;
285 } 307 }
286 308
287 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
288 views::MenuButton::PaintButton(canvas, views::MenuButton::PB_NORMAL);
289 }
290
291 private: 309 private:
292 scoped_ptr<gfx::SlideAnimation> show_animation_; 310 scoped_ptr<gfx::SlideAnimation> show_animation_;
293 311
294 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); 312 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton);
295 }; 313 };
296 314
297 // OverFlowButton (chevron) -------------------------------------------------- 315 // OverFlowButton (chevron) --------------------------------------------------
298 316
299 class OverFlowButton : public views::MenuButton { 317 class OverFlowButton : public views::MenuButton {
300 public: 318 public:
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); 431 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView);
414 }; 432 };
415 433
416 // BookmarkBarView ------------------------------------------------------------ 434 // BookmarkBarView ------------------------------------------------------------
417 435
418 // static 436 // static
419 const int BookmarkBarView::kMaxButtonWidth = 150; 437 const int BookmarkBarView::kMaxButtonWidth = 150;
420 const int BookmarkBarView::kNewtabHorizontalPadding = 2; 438 const int BookmarkBarView::kNewtabHorizontalPadding = 2;
421 const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3; 439 const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3;
422 440
423 static const gfx::ImageSkia& GetDefaultFavicon() { 441 const gfx::ImageSkia& GetDefaultFavicon() {
424 if (!kDefaultFavicon) { 442 if (!kDefaultFavicon) {
425 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 443 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
426 kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON); 444 kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
427 } 445 }
428 return *kDefaultFavicon; 446 return *kDefaultFavicon;
429 } 447 }
430 448
431 static const gfx::ImageSkia& GetFolderIcon() { 449 const gfx::ImageSkia& GetFolderIcon() {
432 if (!kFolderIcon) { 450 if (!kFolderIcon) {
433 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 451 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
434 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); 452 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER);
435 } 453 }
436 return *kFolderIcon; 454 return *kFolderIcon;
437 } 455 }
438 456
439 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) 457 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
440 : page_navigator_(NULL), 458 : page_navigator_(NULL),
441 client_(NULL), 459 client_(NULL),
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 BookmarkNodeChangedImpl(model, node); 1131 BookmarkNodeChangedImpl(model, node);
1114 } 1132 }
1115 1133
1116 void BookmarkBarView::WriteDragDataForView(View* sender, 1134 void BookmarkBarView::WriteDragDataForView(View* sender,
1117 const gfx::Point& press_pt, 1135 const gfx::Point& press_pt,
1118 ui::OSExchangeData* data) { 1136 ui::OSExchangeData* data) {
1119 content::RecordAction(UserMetricsAction("BookmarkBar_DragButton")); 1137 content::RecordAction(UserMetricsAction("BookmarkBar_DragButton"));
1120 1138
1121 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { 1139 for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
1122 if (sender == GetBookmarkButton(i)) { 1140 if (sender == GetBookmarkButton(i)) {
1123 views::TextButton* button = GetBookmarkButton(i); 1141 views::LabelButton* button = GetBookmarkButton(i);
1124 scoped_ptr<gfx::Canvas> canvas( 1142 const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i);
1125 views::GetCanvasForDragImage(button->GetWidget(), button->size())); 1143
1126 button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); 1144 const gfx::Image& image_from_model = model()->GetFavicon(node);
1127 drag_utils::SetDragImageOnDataObject(*canvas, button->size(), 1145 const gfx::ImageSkia& icon = image_from_model.IsEmpty() ?
1128 press_pt.OffsetFromOrigin(), 1146 (node->is_folder() ? GetFolderIcon() : GetDefaultFavicon()) :
1129 data); 1147 *image_from_model.ToImageSkia();
1148
1149 button_drag_utils::SetDragImage(
1150 node->url(),
1151 node->GetTitle(),
1152 icon,
1153 &press_pt,
1154 data,
1155 button->GetWidget());
1130 WriteBookmarkDragData(model()->bookmark_bar_node()->GetChild(i), data); 1156 WriteBookmarkDragData(model()->bookmark_bar_node()->GetChild(i), data);
1131 return; 1157 return;
1132 } 1158 }
1133 } 1159 }
1134 NOTREACHED(); 1160 NOTREACHED();
1135 } 1161 }
1136 1162
1137 int BookmarkBarView::GetDragOperationsForView(View* sender, 1163 int BookmarkBarView::GetDragOperationsForView(View* sender,
1138 const gfx::Point& p) { 1164 const gfx::Point& p) {
1139 if (size_animation_->is_animating() || 1165 if (size_animation_->is_animating() ||
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 } 1371 }
1346 } 1372 }
1347 1373
1348 int BookmarkBarView::GetBookmarkButtonCount() const { 1374 int BookmarkBarView::GetBookmarkButtonCount() const {
1349 // We contain six non-bookmark button views: managed bookmarks, 1375 // We contain six non-bookmark button views: managed bookmarks,
1350 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, 1376 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page,
1351 // and the instruction label. 1377 // and the instruction label.
1352 return child_count() - 6; 1378 return child_count() - 6;
1353 } 1379 }
1354 1380
1355 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { 1381 views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) {
1356 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1382 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
1357 return static_cast<views::TextButton*>(child_at(index)); 1383 return static_cast<views::LabelButton*>(child_at(index));
1358 } 1384 }
1359 1385
1360 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { 1386 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const {
1361 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : 1387 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR :
1362 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; 1388 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR;
1363 } 1389 }
1364 1390
1365 int BookmarkBarView::GetFirstHiddenNodeIndex() { 1391 int BookmarkBarView::GetFirstHiddenNodeIndex() {
1366 const int bb_count = GetBookmarkButtonCount(); 1392 const int bb_count = GetBookmarkButtonCount();
1367 for (int i = 0; i < bb_count; ++i) { 1393 for (int i = 0; i < bb_count; ++i) {
1368 if (!GetBookmarkButton(i)->visible()) 1394 if (!GetBookmarkButton(i)->visible())
1369 return i; 1395 return i;
1370 } 1396 }
1371 return bb_count; 1397 return bb_count;
1372 } 1398 }
1373 1399
1374 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { 1400 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() {
1375 // Title is set in Loaded. 1401 // Title is set in Loaded.
1376 MenuButton* button = 1402 MenuButton* button =
1377 new BookmarkFolderButton(this, base::string16(), this, false); 1403 new BookmarkFolderButton(this, base::string16(), this, false);
1378 button->set_id(VIEW_ID_OTHER_BOOKMARKS); 1404 button->set_id(VIEW_ID_OTHER_BOOKMARKS);
1379 button->SetIcon(GetFolderIcon()); 1405 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
1380 button->set_context_menu_controller(this); 1406 button->set_context_menu_controller(this);
1381 button->set_tag(kOtherFolderButtonTag); 1407 button->set_tag(kOtherFolderButtonTag);
1382 return button; 1408 return button;
1383 } 1409 }
1384 1410
1385 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { 1411 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() {
1386 // Title is set in Loaded. 1412 // Title is set in Loaded.
1387 MenuButton* button = 1413 MenuButton* button =
1388 new BookmarkFolderButton(this, base::string16(), this, false); 1414 new BookmarkFolderButton(this, base::string16(), this, false);
1389 button->set_id(VIEW_ID_MANAGED_BOOKMARKS); 1415 button->set_id(VIEW_ID_MANAGED_BOOKMARKS);
1390 // TODO(joaodasilva): replace with a "managed folder" icon. 1416 // TODO(joaodasilva): replace with a "managed folder" icon.
1391 // http://crbug.com/49598 1417 // http://crbug.com/49598
1392 button->SetIcon(GetFolderIcon()); 1418 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
1393 button->set_context_menu_controller(this); 1419 button->set_context_menu_controller(this);
1394 button->set_tag(kManagedFolderButtonTag); 1420 button->set_tag(kManagedFolderButtonTag);
1395 return button; 1421 return button;
1396 } 1422 }
1397 1423
1398 MenuButton* BookmarkBarView::CreateOverflowButton() { 1424 MenuButton* BookmarkBarView::CreateOverflowButton() {
1399 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1425 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1400 MenuButton* button = new OverFlowButton(this); 1426 MenuButton* button = new OverFlowButton(this);
1401 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); 1427 button->SetImage(views::Button::STATE_NORMAL,
1428 *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS));
1402 1429
1403 // The overflow button's image contains an arrow and therefore it is a 1430 // The overflow button's image contains an arrow and therefore it is a
1404 // direction sensitive image and we need to flip it if the UI layout is 1431 // direction sensitive image and we need to flip it if the UI layout is
1405 // right-to-left. 1432 // right-to-left.
1406 // 1433 //
1407 // By default, menu buttons are not flipped because they generally contain 1434 // By default, menu buttons are not flipped because they generally contain
1408 // text and flipping the gfx::Canvas object will break text rendering. Since 1435 // text and flipping the gfx::Canvas object will break text rendering. Since
1409 // the overflow button does not contain text, we can safely flip it. 1436 // the overflow button does not contain text, we can safely flip it.
1410 button->EnableCanvasFlippingForRTLUI(true); 1437 button->EnableCanvasFlippingForRTLUI(true);
1411 1438
1412 // Make visible as necessary. 1439 // Make visible as necessary.
1413 button->SetVisible(false); 1440 button->SetVisible(false);
1414 // Set accessibility name. 1441 // Set accessibility name.
1415 button->SetAccessibleName( 1442 button->SetAccessibleName(
1416 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON)); 1443 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON));
1417 return button; 1444 return button;
1418 } 1445 }
1419 1446
1420 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { 1447 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) {
1421 if (node->is_url()) { 1448 if (node->is_url()) {
1422 BookmarkButton* button = new BookmarkButton( 1449 BookmarkButton* button = new BookmarkButton(
1423 this, node->url(), node->GetTitle(), browser_->profile()); 1450 this, node->url(), node->GetTitle(), browser_->profile());
1424 ConfigureButton(node, button); 1451 ConfigureButton(node, button);
1425 return button; 1452 return button;
1426 } else { 1453 } else {
1427 views::MenuButton* button = new BookmarkFolderButton( 1454 views::MenuButton* button = new BookmarkFolderButton(
1428 this, node->GetTitle(), this, false); 1455 this, node->GetTitle(), this, false);
1429 button->SetIcon(GetFolderIcon()); 1456 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
1430 ConfigureButton(node, button); 1457 ConfigureButton(node, button);
1431 return button; 1458 return button;
1432 } 1459 }
1433 } 1460 }
1434 1461
1435 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { 1462 views::LabelButton* BookmarkBarView::CreateAppsPageShortcutButton() {
1436 views::TextButton* button = new ShortcutButton( 1463 views::LabelButton* button = new ShortcutButton(
1437 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); 1464 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME));
1438 button->SetTooltipText(l10n_util::GetStringUTF16( 1465 button->SetTooltipText(l10n_util::GetStringUTF16(
1439 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); 1466 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP));
1440 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1467 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1441 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1468 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1442 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT)); 1469 button->SetImage(views::Button::STATE_NORMAL,
1470 *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT));
1443 button->set_context_menu_controller(this); 1471 button->set_context_menu_controller(this);
1444 button->set_tag(kAppsShortcutButtonTag); 1472 button->set_tag(kAppsShortcutButtonTag);
1445 return button; 1473 return button;
1446 } 1474 }
1447 1475
1448 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, 1476 void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
1449 views::TextButton* button) { 1477 views::LabelButton* button) {
1450 button->SetText(node->GetTitle()); 1478 button->SetText(node->GetTitle());
1451 button->SetAccessibleName(node->GetTitle()); 1479 button->SetAccessibleName(node->GetTitle());
1452 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1480 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1453 // We don't always have a theme provider (ui tests, for example). 1481 // We don't always have a theme provider (ui tests, for example).
1454 if (GetThemeProvider()) { 1482 if (GetThemeProvider()) {
1455 button->SetEnabledColor(GetThemeProvider()->GetColor( 1483 button->SetTextColor(
1456 ThemeProperties::COLOR_BOOKMARK_TEXT)); 1484 views::Button::STATE_NORMAL,
1485 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
1457 } 1486 }
1458 1487
1459 button->ClearMaxTextSize(); 1488 button->set_min_size(gfx::Size());
1460 button->set_context_menu_controller(this); 1489 button->set_context_menu_controller(this);
1461 button->set_drag_controller(this); 1490 button->set_drag_controller(this);
1462 if (node->is_url()) { 1491 if (node->is_url()) {
1463 const gfx::Image& favicon = model()->GetFavicon(node); 1492 const gfx::Image& favicon = model()->GetFavicon(node);
1464 if (!favicon.IsEmpty()) 1493 if (!favicon.IsEmpty())
1465 button->SetIcon(*favicon.ToImageSkia()); 1494 button->SetImage(views::Button::STATE_NORMAL, *favicon.ToImageSkia());
1466 else 1495 else
1467 button->SetIcon(GetDefaultFavicon()); 1496 button->SetImage(views::Button::STATE_NORMAL, GetDefaultFavicon());
1468 } 1497 }
1469 button->set_max_width(kMaxButtonWidth); 1498 button->set_max_size(gfx::Size(kMaxButtonWidth, 0));
1470 } 1499 }
1471 1500
1472 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, 1501 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
1473 const BookmarkNode* parent, 1502 const BookmarkNode* parent,
1474 int index) { 1503 int index) {
1475 UpdateButtonsVisibility(); 1504 UpdateButtonsVisibility();
1476 if (parent != model->bookmark_bar_node()) { 1505 if (parent != model->bookmark_bar_node()) {
1477 // We only care about nodes on the bookmark bar. 1506 // We only care about nodes on the bookmark bar.
1478 return; 1507 return;
1479 } 1508 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 } 1540 }
1512 1541
1513 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, 1542 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model,
1514 const BookmarkNode* node) { 1543 const BookmarkNode* node) {
1515 if (node->parent() != model->bookmark_bar_node()) { 1544 if (node->parent() != model->bookmark_bar_node()) {
1516 // We only care about nodes on the bookmark bar. 1545 // We only care about nodes on the bookmark bar.
1517 return; 1546 return;
1518 } 1547 }
1519 int index = model->bookmark_bar_node()->GetIndexOf(node); 1548 int index = model->bookmark_bar_node()->GetIndexOf(node);
1520 DCHECK_NE(-1, index); 1549 DCHECK_NE(-1, index);
1521 views::TextButton* button = GetBookmarkButton(index); 1550 views::LabelButton* button = GetBookmarkButton(index);
1522 gfx::Size old_pref = button->GetPreferredSize(); 1551 gfx::Size old_pref = button->GetPreferredSize();
1523 ConfigureButton(node, button); 1552 ConfigureButton(node, button);
1524 gfx::Size new_pref = button->GetPreferredSize(); 1553 gfx::Size new_pref = button->GetPreferredSize();
1525 if (old_pref.width() != new_pref.width()) { 1554 if (old_pref.width() != new_pref.width()) {
1526 Layout(); 1555 Layout();
1527 SchedulePaint(); 1556 SchedulePaint();
1528 } else if (button->visible()) { 1557 } else if (button->visible()) {
1529 button->SchedulePaint(); 1558 button->SchedulePaint();
1530 } 1559 }
1531 } 1560 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 int ops = node && client_->CanBeEditedByUser(node) ? 1635 int ops = node && client_->CanBeEditedByUser(node) ?
1607 ui::DragDropTypes::DRAG_MOVE : 1636 ui::DragDropTypes::DRAG_MOVE :
1608 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; 1637 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK;
1609 location->operation = chrome::GetPreferredBookmarkDropOperation( 1638 location->operation = chrome::GetPreferredBookmarkDropOperation(
1610 event.source_operations(), ops); 1639 event.source_operations(), ops);
1611 return; 1640 return;
1612 } 1641 }
1613 1642
1614 for (int i = 0; i < GetBookmarkButtonCount() && 1643 for (int i = 0; i < GetBookmarkButtonCount() &&
1615 GetBookmarkButton(i)->visible() && !found; i++) { 1644 GetBookmarkButton(i)->visible() && !found; i++) {
1616 views::TextButton* button = GetBookmarkButton(i); 1645 views::LabelButton* button = GetBookmarkButton(i);
1617 int button_x = mirrored_x - button->x(); 1646 int button_x = mirrored_x - button->x();
1618 int button_w = button->width(); 1647 int button_w = button->width();
1619 if (button_x < button_w) { 1648 if (button_x < button_w) {
1620 found = true; 1649 found = true;
1621 const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i); 1650 const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i);
1622 if (node->is_folder()) { 1651 if (node->is_folder()) {
1623 if (button_x <= views::kDropBetweenPixels) { 1652 if (button_x <= views::kDropBetweenPixels) {
1624 location->index = i; 1653 location->index = i;
1625 } else if (button_x < button_w - views::kDropBetweenPixels) { 1654 } else if (button_x < button_w - views::kDropBetweenPixels) {
1626 location->index = i; 1655 location->index = i;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 return other_bookmarked_button_; 1776 return other_bookmarked_button_;
1748 } 1777 }
1749 1778
1750 void BookmarkBarView::UpdateColors() { 1779 void BookmarkBarView::UpdateColors() {
1751 // We don't always have a theme provider (ui tests, for example). 1780 // We don't always have a theme provider (ui tests, for example).
1752 const ui::ThemeProvider* theme_provider = GetThemeProvider(); 1781 const ui::ThemeProvider* theme_provider = GetThemeProvider();
1753 if (!theme_provider) 1782 if (!theme_provider)
1754 return; 1783 return;
1755 SkColor text_color = 1784 SkColor text_color =
1756 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); 1785 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
1757 for (int i = 0; i < GetBookmarkButtonCount(); ++i) 1786 for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
1758 GetBookmarkButton(i)->SetEnabledColor(text_color); 1787 GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL,
1759 other_bookmarked_button_->SetEnabledColor(text_color); 1788 text_color);
msw 2014/06/11 00:55:45 nit: fits on line above.
1760 managed_bookmarks_button_->SetEnabledColor(text_color); 1789 }
1790 other_bookmarked_button_->SetTextColor(views::Button::STATE_NORMAL,
1791 text_color);
msw 2014/06/11 00:55:46 nit: |color| would make this call and the one belo
1792 managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL,
1793 text_color);
1761 if (apps_page_shortcut_->visible()) 1794 if (apps_page_shortcut_->visible())
1762 apps_page_shortcut_->SetEnabledColor(text_color); 1795 apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, text_color);
1763 } 1796 }
1764 1797
1765 void BookmarkBarView::UpdateButtonsVisibility() { 1798 void BookmarkBarView::UpdateButtonsVisibility() {
1766 bool has_other_children = !model()->other_node()->empty(); 1799 bool has_other_children = !model()->other_node()->empty();
1767 bool update_other = has_other_children != other_bookmarked_button_->visible(); 1800 bool update_other = has_other_children != other_bookmarked_button_->visible();
1768 if (update_other) { 1801 if (update_other) {
1769 other_bookmarked_button_->SetVisible(has_other_children); 1802 other_bookmarked_button_->SetVisible(has_other_children);
1770 UpdateBookmarksSeparatorVisibility(); 1803 UpdateBookmarksSeparatorVisibility();
1771 } 1804 }
1772 1805
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 DCHECK(apps_page_shortcut_); 1936 DCHECK(apps_page_shortcut_);
1904 // Only perform layout if required. 1937 // Only perform layout if required.
1905 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( 1938 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar(
1906 browser_->profile(), browser_->host_desktop_type()); 1939 browser_->profile(), browser_->host_desktop_type());
1907 if (apps_page_shortcut_->visible() == visible) 1940 if (apps_page_shortcut_->visible() == visible)
1908 return; 1941 return;
1909 apps_page_shortcut_->SetVisible(visible); 1942 apps_page_shortcut_->SetVisible(visible);
1910 UpdateBookmarksSeparatorVisibility(); 1943 UpdateBookmarksSeparatorVisibility();
1911 Layout(); 1944 Layout();
1912 } 1945 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698