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