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

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: Disable DragDirectlyToSecondWindow. 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "grit/ui_resources.h" 66 #include "grit/ui_resources.h"
67 #include "ui/accessibility/ax_view_state.h" 67 #include "ui/accessibility/ax_view_state.h"
68 #include "ui/base/dragdrop/drag_utils.h" 68 #include "ui/base/dragdrop/drag_utils.h"
69 #include "ui/base/dragdrop/os_exchange_data.h" 69 #include "ui/base/dragdrop/os_exchange_data.h"
70 #include "ui/base/l10n/l10n_util.h" 70 #include "ui/base/l10n/l10n_util.h"
71 #include "ui/base/resource/resource_bundle.h" 71 #include "ui/base/resource/resource_bundle.h"
72 #include "ui/base/theme_provider.h" 72 #include "ui/base/theme_provider.h"
73 #include "ui/base/window_open_disposition.h" 73 #include "ui/base/window_open_disposition.h"
74 #include "ui/gfx/animation/slide_animation.h" 74 #include "ui/gfx/animation/slide_animation.h"
75 #include "ui/gfx/canvas.h" 75 #include "ui/gfx/canvas.h"
76 #include "ui/gfx/text_constants.h"
76 #include "ui/gfx/text_elider.h" 77 #include "ui/gfx/text_elider.h"
77 #include "ui/views/button_drag_utils.h" 78 #include "ui/views/button_drag_utils.h"
79 #include "ui/views/controls/button/label_button.h"
80 #include "ui/views/controls/button/label_button_border.h"
78 #include "ui/views/controls/button/menu_button.h" 81 #include "ui/views/controls/button/menu_button.h"
79 #include "ui/views/controls/label.h" 82 #include "ui/views/controls/label.h"
80 #include "ui/views/drag_utils.h" 83 #include "ui/views/drag_utils.h"
81 #include "ui/views/metrics.h" 84 #include "ui/views/metrics.h"
82 #include "ui/views/view_constants.h" 85 #include "ui/views/view_constants.h"
83 #include "ui/views/widget/tooltip_manager.h" 86 #include "ui/views/widget/tooltip_manager.h"
84 #include "ui/views/widget/widget.h" 87 #include "ui/views/widget/widget.h"
85 #include "ui/views/window/non_client_view.h" 88 #include "ui/views/window/non_client_view.h"
86 89
87 using base::UserMetricsAction; 90 using base::UserMetricsAction;
88 using content::OpenURLParams; 91 using content::OpenURLParams;
89 using content::PageNavigator; 92 using content::PageNavigator;
90 using content::Referrer; 93 using content::Referrer;
91 using ui::DropTargetEvent; 94 using ui::DropTargetEvent;
92 using views::CustomButton; 95 using views::CustomButton;
96 using views::LabelButtonBorder;
93 using views::MenuButton; 97 using views::MenuButton;
94 using views::View; 98 using views::View;
95 99
96 // Margins around the content. 100 // Margins around the content.
97 static const int kDetachedTopMargin = 1; // When attached, we use 0 and let the 101 static const int kDetachedTopMargin = 1; // When attached, we use 0 and let the
98 // toolbar above serve as the margin. 102 // toolbar above serve as the margin.
99 static const int kBottomMargin = 2; 103 static const int kBottomMargin = 2;
100 static const int kLeftMargin = 1; 104 static const int kLeftMargin = 1;
101 static const int kRightMargin = 1; 105 static const int kRightMargin = 1;
102 106
(...skipping 27 matching lines...) Expand all
130 134
131 // Left-padding for the instructional text. 135 // Left-padding for the instructional text.
132 static const int kInstructionsPadding = 6; 136 static const int kInstructionsPadding = 6;
133 137
134 // Tag for the 'Other bookmarks' button. 138 // Tag for the 'Other bookmarks' button.
135 static const int kOtherFolderButtonTag = 1; 139 static const int kOtherFolderButtonTag = 1;
136 140
137 // Tag for the 'Apps Shortcut' button. 141 // Tag for the 'Apps Shortcut' button.
138 static const int kAppsShortcutButtonTag = 2; 142 static const int kAppsShortcutButtonTag = 2;
139 143
144 // Preferred padding between text and edge.
145 //
146 // Note that the vertical padding is one pixel less than it was in TextButton;
147 // we clip the bottom of letters like 'g' or 'p' if we don't.
148 static const int kButtonPaddingHorizontal = 6;
149 static const int kButtonPaddingVertical = 4;
150
140 // Tag for the 'Managed bookmarks' button. 151 // Tag for the 'Managed bookmarks' button.
141 static const int kManagedFolderButtonTag = 3; 152 static const int kManagedFolderButtonTag = 3;
142 153
143 namespace { 154 namespace {
144 155
145 // To enable/disable BookmarkBar animations during testing. In production 156 // To enable/disable BookmarkBar animations during testing. In production
146 // animations are enabled by default. 157 // animations are enabled by default.
147 bool animations_enabled = true; 158 bool animations_enabled = true;
148 159
149 // BookmarkButtonBase ----------------------------------------------- 160 // BookmarkButtonBase -----------------------------------------------
150 161
151 // Base class for text buttons used on the bookmark bar. 162 // Base class for text buttons used on the bookmark bar.
152 163
153 class BookmarkButtonBase : public views::TextButton { 164 class BookmarkButtonBase : public views::LabelButton {
154 public: 165 public:
155 BookmarkButtonBase(views::ButtonListener* listener, 166 BookmarkButtonBase(views::ButtonListener* listener,
156 const base::string16& title) 167 const base::string16& title)
157 : TextButton(listener, title) { 168 : LabelButton(listener, title) {
169 SetElideBehavior(gfx::FADE_TAIL);
158 show_animation_.reset(new gfx::SlideAnimation(this)); 170 show_animation_.reset(new gfx::SlideAnimation(this));
159 if (!animations_enabled) { 171 if (!animations_enabled) {
160 // For some reason during testing the events generated by animating 172 // For some reason during testing the events generated by animating
161 // throw off the test. So, don't animate while testing. 173 // throw off the test. So, don't animate while testing.
162 show_animation_->Reset(1); 174 show_animation_->Reset(1);
163 } else { 175 } else {
164 show_animation_->Show(); 176 show_animation_->Show();
165 } 177 }
166 } 178 }
167 179
168 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { 180 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE {
169 return e.type() == ui::ET_GESTURE_TAP || 181 return e.type() == ui::ET_GESTURE_TAP ||
170 e.type() == ui::ET_GESTURE_TAP_DOWN || 182 e.type() == ui::ET_GESTURE_TAP_DOWN ||
171 event_utils::IsPossibleDispositionEvent(e); 183 event_utils::IsPossibleDispositionEvent(e);
172 } 184 }
173 185
186 virtual scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const OVERRIDE {
187 // We change the insets on the border to match the previous TextButton.
188 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder();
189 border->set_insets(gfx::Insets(kButtonPaddingVertical,
190 kButtonPaddingHorizontal,
191 kButtonPaddingVertical,
192 kButtonPaddingHorizontal));
193 return border.Pass();
194 }
195
174 private: 196 private:
175 scoped_ptr<gfx::SlideAnimation> show_animation_; 197 scoped_ptr<gfx::SlideAnimation> show_animation_;
176 198
177 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); 199 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase);
178 }; 200 };
179 201
180 // BookmarkButton ------------------------------------------------------------- 202 // BookmarkButton -------------------------------------------------------------
181 203
182 // Buttons used for the bookmarks on the bookmark bar. 204 // Buttons used for the bookmarks on the bookmark bar.
183 205
184 class BookmarkButton : public BookmarkButtonBase { 206 class BookmarkButton : public BookmarkButtonBase {
185 public: 207 public:
186 // The internal view class name. 208 // The internal view class name.
187 static const char kViewClassName[]; 209 static const char kViewClassName[];
188 210
189 BookmarkButton(views::ButtonListener* listener, 211 BookmarkButton(views::ButtonListener* listener,
190 const GURL& url, 212 const GURL& url,
191 const base::string16& title, 213 const base::string16& title,
192 Profile* profile) 214 Profile* profile)
193 : BookmarkButtonBase(listener, title), 215 : BookmarkButtonBase(listener, title),
194 url_(url), 216 url_(url),
195 profile_(profile) { 217 profile_(profile) {
196 } 218 }
197 219
198 virtual bool GetTooltipText(const gfx::Point& p, 220 virtual bool GetTooltipText(const gfx::Point& p,
199 base::string16* tooltip) const OVERRIDE { 221 base::string16* tooltip) const OVERRIDE {
200 gfx::Point location(p); 222 gfx::Point location(p);
201 ConvertPointToScreen(this, &location); 223 ConvertPointToScreen(this, &location);
202 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( 224 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle(
203 GetWidget(), location, url_, text(), profile_); 225 GetWidget(), location, url_, GetText(), profile_);
204 return !tooltip->empty(); 226 return !tooltip->empty();
205 } 227 }
206 228
207 virtual const char* GetClassName() const OVERRIDE { 229 virtual const char* GetClassName() const OVERRIDE {
208 return kViewClassName; 230 return kViewClassName;
209 } 231 }
210 232
211 private: 233 private:
212 const GURL& url_; 234 const GURL& url_;
213 Profile* profile_; 235 Profile* profile_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // For some reason during testing the events generated by animating 282 // For some reason during testing the events generated by animating
261 // throw off the test. So, don't animate while testing. 283 // throw off the test. So, don't animate while testing.
262 show_animation_->Reset(1); 284 show_animation_->Reset(1);
263 } else { 285 } else {
264 show_animation_->Show(); 286 show_animation_->Show();
265 } 287 }
266 } 288 }
267 289
268 virtual bool GetTooltipText(const gfx::Point& p, 290 virtual bool GetTooltipText(const gfx::Point& p,
269 base::string16* tooltip) const OVERRIDE { 291 base::string16* tooltip) const OVERRIDE {
270 if (text_size_.width() > GetTextBounds().width()) 292 if (label()->GetPreferredSize().width() > label()->size().width())
271 *tooltip = text_; 293 *tooltip = GetText();
272 return !tooltip->empty(); 294 return !tooltip->empty();
273 } 295 }
274 296
275 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { 297 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE {
276 // Left clicks and taps should show the menu contents and right clicks 298 // Left clicks and taps should show the menu contents and right clicks
277 // should show the context menu. They should not trigger the opening of 299 // should show the context menu. They should not trigger the opening of
278 // underlying urls. 300 // underlying urls.
279 if (e.type() == ui::ET_GESTURE_TAP || 301 if (e.type() == ui::ET_GESTURE_TAP ||
280 (e.IsMouseEvent() && (e.flags() & 302 (e.IsMouseEvent() && (e.flags() &
281 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) 303 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON))))
282 return false; 304 return false;
283 305
284 if (e.IsMouseEvent()) 306 if (e.IsMouseEvent())
285 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; 307 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB;
286 return false; 308 return false;
287 } 309 }
288 310
289 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
290 views::MenuButton::PaintButton(canvas, views::MenuButton::PB_NORMAL);
291 }
292
293 private: 311 private:
294 scoped_ptr<gfx::SlideAnimation> show_animation_; 312 scoped_ptr<gfx::SlideAnimation> show_animation_;
295 313
296 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); 314 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton);
297 }; 315 };
298 316
299 // OverFlowButton (chevron) -------------------------------------------------- 317 // OverFlowButton (chevron) --------------------------------------------------
300 318
301 class OverFlowButton : public views::MenuButton { 319 class OverFlowButton : public views::MenuButton {
302 public: 320 public:
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); 433 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView);
416 }; 434 };
417 435
418 // BookmarkBarView ------------------------------------------------------------ 436 // BookmarkBarView ------------------------------------------------------------
419 437
420 // static 438 // static
421 const int BookmarkBarView::kMaxButtonWidth = 150; 439 const int BookmarkBarView::kMaxButtonWidth = 150;
422 const int BookmarkBarView::kNewtabHorizontalPadding = 2; 440 const int BookmarkBarView::kNewtabHorizontalPadding = 2;
423 const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3; 441 const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3;
424 442
425 static const gfx::ImageSkia& GetDefaultFavicon() { 443 const gfx::ImageSkia& GetDefaultFavicon() {
426 if (!kDefaultFavicon) { 444 if (!kDefaultFavicon) {
427 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 445 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
428 kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON); 446 kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
429 } 447 }
430 return *kDefaultFavicon; 448 return *kDefaultFavicon;
431 } 449 }
432 450
433 static const gfx::ImageSkia& GetFolderIcon() { 451 const gfx::ImageSkia& GetFolderIcon() {
434 if (!kFolderIcon) { 452 if (!kFolderIcon) {
435 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 453 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
436 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); 454 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER);
437 } 455 }
438 return *kFolderIcon; 456 return *kFolderIcon;
439 } 457 }
440 458
441 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) 459 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
442 : page_navigator_(NULL), 460 : page_navigator_(NULL),
443 client_(NULL), 461 client_(NULL),
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 BookmarkNodeChangedImpl(model, node); 1133 BookmarkNodeChangedImpl(model, node);
1116 } 1134 }
1117 1135
1118 void BookmarkBarView::WriteDragDataForView(View* sender, 1136 void BookmarkBarView::WriteDragDataForView(View* sender,
1119 const gfx::Point& press_pt, 1137 const gfx::Point& press_pt,
1120 ui::OSExchangeData* data) { 1138 ui::OSExchangeData* data) {
1121 content::RecordAction(UserMetricsAction("BookmarkBar_DragButton")); 1139 content::RecordAction(UserMetricsAction("BookmarkBar_DragButton"));
1122 1140
1123 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { 1141 for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
1124 if (sender == GetBookmarkButton(i)) { 1142 if (sender == GetBookmarkButton(i)) {
1125 views::TextButton* button = GetBookmarkButton(i); 1143 views::LabelButton* button = GetBookmarkButton(i);
1126 scoped_ptr<gfx::Canvas> canvas( 1144 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i);
1127 views::GetCanvasForDragImage(button->GetWidget(), button->size())); 1145
1128 button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); 1146 const gfx::Image& image_from_model = model_->GetFavicon(node);
1129 drag_utils::SetDragImageOnDataObject(*canvas, 1147 const gfx::ImageSkia& icon = image_from_model.IsEmpty() ?
1130 press_pt.OffsetFromOrigin(), 1148 (node->is_folder() ? GetFolderIcon() : GetDefaultFavicon()) :
1131 data); 1149 *image_from_model.ToImageSkia();
1150
1151 button_drag_utils::SetDragImage(
1152 node->url(),
1153 node->GetTitle(),
1154 icon,
1155 &press_pt,
1156 data,
1157 button->GetWidget());
1132 WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data); 1158 WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data);
1133 return; 1159 return;
1134 } 1160 }
1135 } 1161 }
1136 NOTREACHED(); 1162 NOTREACHED();
1137 } 1163 }
1138 1164
1139 int BookmarkBarView::GetDragOperationsForView(View* sender, 1165 int BookmarkBarView::GetDragOperationsForView(View* sender,
1140 const gfx::Point& p) { 1166 const gfx::Point& p) {
1141 if (size_animation_->is_animating() || 1167 if (size_animation_->is_animating() ||
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 } 1377 }
1352 } 1378 }
1353 1379
1354 int BookmarkBarView::GetBookmarkButtonCount() const { 1380 int BookmarkBarView::GetBookmarkButtonCount() const {
1355 // We contain six non-bookmark button views: managed bookmarks, 1381 // We contain six non-bookmark button views: managed bookmarks,
1356 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, 1382 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page,
1357 // and the instruction label. 1383 // and the instruction label.
1358 return child_count() - 6; 1384 return child_count() - 6;
1359 } 1385 }
1360 1386
1361 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { 1387 views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) {
1362 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1388 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
1363 return static_cast<views::TextButton*>(child_at(index)); 1389 return static_cast<views::LabelButton*>(child_at(index));
1364 } 1390 }
1365 1391
1366 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { 1392 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const {
1367 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : 1393 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR :
1368 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; 1394 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR;
1369 } 1395 }
1370 1396
1371 int BookmarkBarView::GetFirstHiddenNodeIndex() { 1397 int BookmarkBarView::GetFirstHiddenNodeIndex() {
1372 const int bb_count = GetBookmarkButtonCount(); 1398 const int bb_count = GetBookmarkButtonCount();
1373 for (int i = 0; i < bb_count; ++i) { 1399 for (int i = 0; i < bb_count; ++i) {
1374 if (!GetBookmarkButton(i)->visible()) 1400 if (!GetBookmarkButton(i)->visible())
1375 return i; 1401 return i;
1376 } 1402 }
1377 return bb_count; 1403 return bb_count;
1378 } 1404 }
1379 1405
1380 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { 1406 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() {
1381 // Title is set in Loaded. 1407 // Title is set in Loaded.
1382 MenuButton* button = 1408 MenuButton* button =
1383 new BookmarkFolderButton(this, base::string16(), this, false); 1409 new BookmarkFolderButton(this, base::string16(), this, false);
1384 button->set_id(VIEW_ID_OTHER_BOOKMARKS); 1410 button->set_id(VIEW_ID_OTHER_BOOKMARKS);
1385 button->SetIcon(GetFolderIcon()); 1411 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
1386 button->set_context_menu_controller(this); 1412 button->set_context_menu_controller(this);
1387 button->set_tag(kOtherFolderButtonTag); 1413 button->set_tag(kOtherFolderButtonTag);
1388 return button; 1414 return button;
1389 } 1415 }
1390 1416
1391 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { 1417 MenuButton* BookmarkBarView::CreateManagedBookmarksButton() {
1392 // Title is set in Loaded. 1418 // Title is set in Loaded.
1393 MenuButton* button = 1419 MenuButton* button =
1394 new BookmarkFolderButton(this, base::string16(), this, false); 1420 new BookmarkFolderButton(this, base::string16(), this, false);
1395 button->set_id(VIEW_ID_MANAGED_BOOKMARKS); 1421 button->set_id(VIEW_ID_MANAGED_BOOKMARKS);
1396 // TODO(joaodasilva): replace with a "managed folder" icon. 1422 // TODO(joaodasilva): replace with a "managed folder" icon.
1397 // http://crbug.com/49598 1423 // http://crbug.com/49598
1398 button->SetIcon(GetFolderIcon()); 1424 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
1399 button->set_context_menu_controller(this); 1425 button->set_context_menu_controller(this);
1400 button->set_tag(kManagedFolderButtonTag); 1426 button->set_tag(kManagedFolderButtonTag);
1401 return button; 1427 return button;
1402 } 1428 }
1403 1429
1404 MenuButton* BookmarkBarView::CreateOverflowButton() { 1430 MenuButton* BookmarkBarView::CreateOverflowButton() {
1405 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1431 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1406 MenuButton* button = new OverFlowButton(this); 1432 MenuButton* button = new OverFlowButton(this);
1407 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); 1433 button->SetImage(views::Button::STATE_NORMAL,
1434 *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS));
1408 1435
1409 // The overflow button's image contains an arrow and therefore it is a 1436 // The overflow button's image contains an arrow and therefore it is a
1410 // direction sensitive image and we need to flip it if the UI layout is 1437 // direction sensitive image and we need to flip it if the UI layout is
1411 // right-to-left. 1438 // right-to-left.
1412 // 1439 //
1413 // By default, menu buttons are not flipped because they generally contain 1440 // By default, menu buttons are not flipped because they generally contain
1414 // text and flipping the gfx::Canvas object will break text rendering. Since 1441 // text and flipping the gfx::Canvas object will break text rendering. Since
1415 // the overflow button does not contain text, we can safely flip it. 1442 // the overflow button does not contain text, we can safely flip it.
1416 button->EnableCanvasFlippingForRTLUI(true); 1443 button->EnableCanvasFlippingForRTLUI(true);
1417 1444
1418 // Make visible as necessary. 1445 // Make visible as necessary.
1419 button->SetVisible(false); 1446 button->SetVisible(false);
1420 // Set accessibility name. 1447 // Set accessibility name.
1421 button->SetAccessibleName( 1448 button->SetAccessibleName(
1422 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON)); 1449 l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS_CHEVRON));
1423 return button; 1450 return button;
1424 } 1451 }
1425 1452
1426 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { 1453 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) {
1427 if (node->is_url()) { 1454 if (node->is_url()) {
1428 BookmarkButton* button = new BookmarkButton( 1455 BookmarkButton* button = new BookmarkButton(
1429 this, node->url(), node->GetTitle(), browser_->profile()); 1456 this, node->url(), node->GetTitle(), browser_->profile());
1430 ConfigureButton(node, button); 1457 ConfigureButton(node, button);
1431 return button; 1458 return button;
1432 } else { 1459 } else {
1433 views::MenuButton* button = new BookmarkFolderButton( 1460 views::MenuButton* button = new BookmarkFolderButton(
1434 this, node->GetTitle(), this, false); 1461 this, node->GetTitle(), this, false);
1435 button->SetIcon(GetFolderIcon()); 1462 button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
1436 ConfigureButton(node, button); 1463 ConfigureButton(node, button);
1437 return button; 1464 return button;
1438 } 1465 }
1439 } 1466 }
1440 1467
1441 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { 1468 views::LabelButton* BookmarkBarView::CreateAppsPageShortcutButton() {
1442 views::TextButton* button = new ShortcutButton( 1469 views::LabelButton* button = new ShortcutButton(
1443 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); 1470 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME));
1444 button->SetTooltipText(l10n_util::GetStringUTF16( 1471 button->SetTooltipText(l10n_util::GetStringUTF16(
1445 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); 1472 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP));
1446 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1473 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1447 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1474 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1448 button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT)); 1475 button->SetImage(views::Button::STATE_NORMAL,
1476 *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT));
1449 button->set_context_menu_controller(this); 1477 button->set_context_menu_controller(this);
1450 button->set_tag(kAppsShortcutButtonTag); 1478 button->set_tag(kAppsShortcutButtonTag);
1451 return button; 1479 return button;
1452 } 1480 }
1453 1481
1454 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, 1482 void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
1455 views::TextButton* button) { 1483 views::LabelButton* button) {
1456 button->SetText(node->GetTitle()); 1484 button->SetText(node->GetTitle());
1457 button->SetAccessibleName(node->GetTitle()); 1485 button->SetAccessibleName(node->GetTitle());
1458 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1486 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1459 // We don't always have a theme provider (ui tests, for example). 1487 // We don't always have a theme provider (ui tests, for example).
1460 if (GetThemeProvider()) { 1488 if (GetThemeProvider()) {
1461 button->SetEnabledColor(GetThemeProvider()->GetColor( 1489 button->SetTextColor(
1462 ThemeProperties::COLOR_BOOKMARK_TEXT)); 1490 views::Button::STATE_NORMAL,
1491 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
1463 } 1492 }
1464 1493
1465 button->ClearMaxTextSize(); 1494 button->set_min_size(gfx::Size());
1466 button->set_context_menu_controller(this); 1495 button->set_context_menu_controller(this);
1467 button->set_drag_controller(this); 1496 button->set_drag_controller(this);
1468 if (node->is_url()) { 1497 if (node->is_url()) {
1469 const gfx::Image& favicon = model_->GetFavicon(node); 1498 const gfx::Image& favicon = model_->GetFavicon(node);
1470 if (!favicon.IsEmpty()) 1499 if (!favicon.IsEmpty())
1471 button->SetIcon(*favicon.ToImageSkia()); 1500 button->SetImage(views::Button::STATE_NORMAL, *favicon.ToImageSkia());
1472 else 1501 else
1473 button->SetIcon(GetDefaultFavicon()); 1502 button->SetImage(views::Button::STATE_NORMAL, GetDefaultFavicon());
1474 } 1503 }
1475 button->set_max_width(kMaxButtonWidth); 1504 button->set_max_size(gfx::Size(kMaxButtonWidth, 0));
1476 } 1505 }
1477 1506
1478 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, 1507 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
1479 const BookmarkNode* parent, 1508 const BookmarkNode* parent,
1480 int index) { 1509 int index) {
1481 UpdateButtonsVisibility(); 1510 UpdateButtonsVisibility();
1482 if (parent != model->bookmark_bar_node()) { 1511 if (parent != model->bookmark_bar_node()) {
1483 // We only care about nodes on the bookmark bar. 1512 // We only care about nodes on the bookmark bar.
1484 return; 1513 return;
1485 } 1514 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); 1554 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle());
1526 return; 1555 return;
1527 } 1556 }
1528 1557
1529 if (node->parent() != model->bookmark_bar_node()) { 1558 if (node->parent() != model->bookmark_bar_node()) {
1530 // We only care about nodes on the bookmark bar. 1559 // We only care about nodes on the bookmark bar.
1531 return; 1560 return;
1532 } 1561 }
1533 int index = model->bookmark_bar_node()->GetIndexOf(node); 1562 int index = model->bookmark_bar_node()->GetIndexOf(node);
1534 DCHECK_NE(-1, index); 1563 DCHECK_NE(-1, index);
1535 views::TextButton* button = GetBookmarkButton(index); 1564 views::LabelButton* button = GetBookmarkButton(index);
1536 gfx::Size old_pref = button->GetPreferredSize(); 1565 gfx::Size old_pref = button->GetPreferredSize();
1537 ConfigureButton(node, button); 1566 ConfigureButton(node, button);
1538 gfx::Size new_pref = button->GetPreferredSize(); 1567 gfx::Size new_pref = button->GetPreferredSize();
1539 if (old_pref.width() != new_pref.width()) { 1568 if (old_pref.width() != new_pref.width()) {
1540 Layout(); 1569 Layout();
1541 SchedulePaint(); 1570 SchedulePaint();
1542 } else if (button->visible()) { 1571 } else if (button->visible()) {
1543 button->SchedulePaint(); 1572 button->SchedulePaint();
1544 } 1573 }
1545 } 1574 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 int ops = node && client_->CanBeEditedByUser(node) ? 1649 int ops = node && client_->CanBeEditedByUser(node) ?
1621 ui::DragDropTypes::DRAG_MOVE : 1650 ui::DragDropTypes::DRAG_MOVE :
1622 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; 1651 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK;
1623 location->operation = chrome::GetPreferredBookmarkDropOperation( 1652 location->operation = chrome::GetPreferredBookmarkDropOperation(
1624 event.source_operations(), ops); 1653 event.source_operations(), ops);
1625 return; 1654 return;
1626 } 1655 }
1627 1656
1628 for (int i = 0; i < GetBookmarkButtonCount() && 1657 for (int i = 0; i < GetBookmarkButtonCount() &&
1629 GetBookmarkButton(i)->visible() && !found; i++) { 1658 GetBookmarkButton(i)->visible() && !found; i++) {
1630 views::TextButton* button = GetBookmarkButton(i); 1659 views::LabelButton* button = GetBookmarkButton(i);
1631 int button_x = mirrored_x - button->x(); 1660 int button_x = mirrored_x - button->x();
1632 int button_w = button->width(); 1661 int button_w = button->width();
1633 if (button_x < button_w) { 1662 if (button_x < button_w) {
1634 found = true; 1663 found = true;
1635 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); 1664 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i);
1636 if (node->is_folder()) { 1665 if (node->is_folder()) {
1637 if (button_x <= views::kDropBetweenPixels) { 1666 if (button_x <= views::kDropBetweenPixels) {
1638 location->index = i; 1667 location->index = i;
1639 } else if (button_x < button_w - views::kDropBetweenPixels) { 1668 } else if (button_x < button_w - views::kDropBetweenPixels) {
1640 location->index = i; 1669 location->index = i;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 return managed_bookmarks_button_; 1788 return managed_bookmarks_button_;
1760 // Node wasn't on the bookmark bar, use the other bookmark button. 1789 // Node wasn't on the bookmark bar, use the other bookmark button.
1761 return other_bookmarked_button_; 1790 return other_bookmarked_button_;
1762 } 1791 }
1763 1792
1764 void BookmarkBarView::UpdateColors() { 1793 void BookmarkBarView::UpdateColors() {
1765 // We don't always have a theme provider (ui tests, for example). 1794 // We don't always have a theme provider (ui tests, for example).
1766 const ui::ThemeProvider* theme_provider = GetThemeProvider(); 1795 const ui::ThemeProvider* theme_provider = GetThemeProvider();
1767 if (!theme_provider) 1796 if (!theme_provider)
1768 return; 1797 return;
1769 SkColor text_color = 1798 SkColor color =
1770 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); 1799 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
1771 for (int i = 0; i < GetBookmarkButtonCount(); ++i) 1800 for (int i = 0; i < GetBookmarkButtonCount(); ++i)
1772 GetBookmarkButton(i)->SetEnabledColor(text_color); 1801 GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, color);
1773 other_bookmarked_button_->SetEnabledColor(text_color); 1802 other_bookmarked_button_->SetTextColor(views::Button::STATE_NORMAL, color);
1774 managed_bookmarks_button_->SetEnabledColor(text_color); 1803 managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color);
1775 if (apps_page_shortcut_->visible()) 1804 if (apps_page_shortcut_->visible())
1776 apps_page_shortcut_->SetEnabledColor(text_color); 1805 apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, color);
1777 } 1806 }
1778 1807
1779 void BookmarkBarView::UpdateButtonsVisibility() { 1808 void BookmarkBarView::UpdateButtonsVisibility() {
1780 bool has_other_children = !model_->other_node()->empty(); 1809 bool has_other_children = !model_->other_node()->empty();
1781 bool update_other = has_other_children != other_bookmarked_button_->visible(); 1810 bool update_other = has_other_children != other_bookmarked_button_->visible();
1782 if (update_other) { 1811 if (update_other) {
1783 other_bookmarked_button_->SetVisible(has_other_children); 1812 other_bookmarked_button_->SetVisible(has_other_children);
1784 UpdateBookmarksSeparatorVisibility(); 1813 UpdateBookmarksSeparatorVisibility();
1785 } 1814 }
1786 1815
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 DCHECK(apps_page_shortcut_); 1947 DCHECK(apps_page_shortcut_);
1919 // Only perform layout if required. 1948 // Only perform layout if required.
1920 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( 1949 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar(
1921 browser_->profile(), browser_->host_desktop_type()); 1950 browser_->profile(), browser_->host_desktop_type());
1922 if (apps_page_shortcut_->visible() == visible) 1951 if (apps_page_shortcut_->visible() == visible)
1923 return; 1952 return;
1924 apps_page_shortcut_->SetVisible(visible); 1953 apps_page_shortcut_->SetVisible(visible);
1925 UpdateBookmarksSeparatorVisibility(); 1954 UpdateBookmarksSeparatorVisibility();
1926 Layout(); 1955 Layout();
1927 } 1956 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.h ('k') | chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698