OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/bookmark_bar_view.h" | 5 #include "chrome/browser/views/bookmark_bar_view.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/base_drag_source.h" | 9 #include "base/base_drag_source.h" |
10 #include "base/gfx/skia_utils.h" | 10 #include "base/gfx/skia_utils.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // Border color along the left edge of the view representing the most recently | 136 // Border color along the left edge of the view representing the most recently |
137 // view pages. | 137 // view pages. |
138 static const SkColor kSeparatorColor = SkColorSetRGB(194, 205, 212); | 138 static const SkColor kSeparatorColor = SkColorSetRGB(194, 205, 212); |
139 | 139 |
140 // Left-padding for the instructional text. | 140 // Left-padding for the instructional text. |
141 static const int kInstructionsPadding = 6; | 141 static const int kInstructionsPadding = 6; |
142 | 142 |
143 // Color of the instructional text. | 143 // Color of the instructional text. |
144 static const SkColor kInstructionsColor = SkColorSetRGB(128, 128, 142); | 144 static const SkColor kInstructionsColor = SkColorSetRGB(128, 128, 142); |
145 | 145 |
| 146 // Tag for the other button. |
| 147 static const int kOtherFolderButtonTag = 1; |
| 148 |
146 namespace { | 149 namespace { |
147 | 150 |
148 // Calculates the drop operation given the event and supported set of | 151 // Calculates the drop operation given the event and supported set of |
149 // operations. | 152 // operations. |
150 int PreferredDropOperation(const DropTargetEvent& event, int operation) { | 153 int PreferredDropOperation(const DropTargetEvent& event, int operation) { |
151 int common_ops = (event.GetSourceOperations() & operation); | 154 int common_ops = (event.GetSourceOperations() & operation); |
152 if (!common_ops) | 155 if (!common_ops) |
153 return 0; | 156 return 0; |
154 if (DragDropTypes::DRAG_COPY & common_ops) | 157 if (DragDropTypes::DRAG_COPY & common_ops) |
155 return DragDropTypes::DRAG_COPY; | 158 return DragDropTypes::DRAG_COPY; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return !tooltip->empty(); | 250 return !tooltip->empty(); |
248 } | 251 } |
249 | 252 |
250 virtual bool IsTriggerableEvent(const ChromeViews::MouseEvent& e) { | 253 virtual bool IsTriggerableEvent(const ChromeViews::MouseEvent& e) { |
251 return event_utils::IsPossibleDispositionEvent(e); | 254 return event_utils::IsPossibleDispositionEvent(e); |
252 } | 255 } |
253 | 256 |
254 virtual void Paint(ChromeCanvas *canvas) { | 257 virtual void Paint(ChromeCanvas *canvas) { |
255 ChromeViews::TextButton::Paint(canvas); | 258 ChromeViews::TextButton::Paint(canvas); |
256 | 259 |
| 260 PaintAnimation(this, canvas, show_animation_->GetCurrentValue()); |
| 261 } |
| 262 |
| 263 static void PaintAnimation(ChromeViews::View* view, |
| 264 ChromeCanvas* canvas, |
| 265 double animation_value) { |
257 // Since we can't change the alpha of the button (it contains un-alphable | 266 // Since we can't change the alpha of the button (it contains un-alphable |
258 // text), we paint the bar background over the front of the button. As the | 267 // text), we paint the bar background over the front of the button. As the |
259 // bar background is a gradient, we have to paint the gradient at the | 268 // bar background is a gradient, we have to paint the gradient at the |
260 // size of the parent (hence all the margin math below). We can't use | 269 // size of the parent (hence all the margin math below). We can't use |
261 // the parent's actual bounds because they differ from what is painted. | 270 // the parent's actual bounds because they differ from what is painted. |
262 SkPaint paint; | 271 SkPaint paint; |
263 paint.setAlpha(static_cast<int>( | 272 paint.setAlpha(static_cast<int>((1.0 - animation_value) * 255)); |
264 (1.0 - show_animation_->GetCurrentValue()) * 255)); | |
265 paint.setShader(gfx::CreateGradientShader(0, | 273 paint.setShader(gfx::CreateGradientShader(0, |
266 height() + kTopMargin + kBottomMargin, | 274 view->height() + kTopMargin + kBottomMargin, |
267 kTopBorderColor, | 275 kTopBorderColor, |
268 kBackgroundColor))->safeUnref(); | 276 kBackgroundColor))->safeUnref(); |
269 canvas->FillRectInt(0, -kTopMargin, width(), | 277 canvas->FillRectInt(0, -kTopMargin, view->width(), |
270 height() + kTopMargin + kBottomMargin, paint); | 278 view->height() + kTopMargin + kBottomMargin, paint); |
271 } | |
272 | |
273 virtual void AnimationProgressed(const Animation* animation) { | |
274 ChromeViews::TextButton::AnimationProgressed(animation); | |
275 SchedulePaint(); | |
276 } | 279 } |
277 | 280 |
278 private: | 281 private: |
279 const GURL& url_; | 282 const GURL& url_; |
280 Profile* profile_; | 283 Profile* profile_; |
281 scoped_ptr<SlideAnimation> show_animation_; | 284 scoped_ptr<SlideAnimation> show_animation_; |
282 | 285 |
283 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 286 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
284 }; | 287 }; |
285 | 288 |
| 289 // BookmarkFolderButton ------------------------------------------------------- |
| 290 |
| 291 // Buttons used for folders on the bookmark bar, including the 'other folders' |
| 292 // button. |
| 293 class BookmarkFolderButton : public ChromeViews::MenuButton { |
| 294 public: |
| 295 BookmarkFolderButton(const std::wstring& title, |
| 296 ChromeViews::ViewMenuDelegate* menu_delegate, |
| 297 bool show_menu_marker) |
| 298 : MenuButton(title, menu_delegate, show_menu_marker) { |
| 299 show_animation_.reset(new SlideAnimation(this)); |
| 300 if (BookmarkBarView::testing_) { |
| 301 // For some reason during testing the events generated by animating |
| 302 // throw off the test. So, don't animate while testing. |
| 303 show_animation_->Reset(1); |
| 304 } else { |
| 305 show_animation_->Show(); |
| 306 } |
| 307 } |
| 308 |
| 309 virtual bool IsTriggerableEvent(const ChromeViews::MouseEvent& e) { |
| 310 // This is hard coded to avoid potential notification on left mouse down, |
| 311 // which we want to show the menu. |
| 312 return e.IsMiddleMouseButton(); |
| 313 } |
| 314 |
| 315 virtual void Paint(ChromeCanvas *canvas) { |
| 316 ChromeViews::MenuButton::Paint(canvas, false); |
| 317 |
| 318 BookmarkButton::PaintAnimation(this, canvas, |
| 319 show_animation_->GetCurrentValue()); |
| 320 } |
| 321 |
| 322 private: |
| 323 scoped_ptr<SlideAnimation> show_animation_; |
| 324 |
| 325 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
| 326 }; |
| 327 |
286 // DropInfo ------------------------------------------------------------------- | 328 // DropInfo ------------------------------------------------------------------- |
287 | 329 |
288 // Tracks drops on the BookmarkBarView. | 330 // Tracks drops on the BookmarkBarView. |
289 | 331 |
290 struct DropInfo { | 332 struct DropInfo { |
291 DropInfo() : drop_index(-1), is_menu_showing(false), valid(false) {} | 333 DropInfo() : drop_index(-1), is_menu_showing(false), valid(false) {} |
292 | 334 |
293 // Whether the data is valid. | 335 // Whether the data is valid. |
294 bool valid; | 336 bool valid; |
295 | 337 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 421 } |
380 | 422 |
381 private: | 423 private: |
382 // Creates an entry in menu for each child node of parent starting at | 424 // Creates an entry in menu for each child node of parent starting at |
383 // start_child_index, recursively invoking this for any star groups. | 425 // start_child_index, recursively invoking this for any star groups. |
384 void BuildMenu(BookmarkNode* parent, | 426 void BuildMenu(BookmarkNode* parent, |
385 int start_child_index, | 427 int start_child_index, |
386 MenuItemView* menu, | 428 MenuItemView* menu, |
387 int* next_menu_id) { | 429 int* next_menu_id) { |
388 DCHECK(!parent->GetChildCount() || | 430 DCHECK(!parent->GetChildCount() || |
| 431 |
389 start_child_index < parent->GetChildCount()); | 432 start_child_index < parent->GetChildCount()); |
390 for (int i = start_child_index; i < parent->GetChildCount(); ++i) { | 433 for (int i = start_child_index; i < parent->GetChildCount(); ++i) { |
391 BookmarkNode* node = parent->GetChild(i); | 434 BookmarkNode* node = parent->GetChild(i); |
392 int id = *next_menu_id; | 435 int id = *next_menu_id; |
393 | 436 |
394 (*next_menu_id)++; | 437 (*next_menu_id)++; |
395 if (node->GetType() == history::StarredEntry::URL) { | 438 if (node->GetType() == history::StarredEntry::URL) { |
396 SkBitmap icon = node->GetFavIcon(); | 439 SkBitmap icon = node->GetFavIcon(); |
397 if (icon.width() == 0) | 440 if (icon.width() == 0) |
398 icon = *kDefaultFavIcon; | 441 icon = *kDefaultFavIcon; |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 rb.GetFont(ResourceBundle::BaseFont)); | 1163 rb.GetFont(ResourceBundle::BaseFont)); |
1121 instructions_->SetColor(kInstructionsColor); | 1164 instructions_->SetColor(kInstructionsColor); |
1122 AddChildView(instructions_); | 1165 AddChildView(instructions_); |
1123 | 1166 |
1124 SetContextMenuController(this); | 1167 SetContextMenuController(this); |
1125 | 1168 |
1126 size_animation_.reset(new SlideAnimation(this)); | 1169 size_animation_.reset(new SlideAnimation(this)); |
1127 } | 1170 } |
1128 | 1171 |
1129 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { | 1172 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { |
1130 MenuButton* button = new MenuButton( | 1173 MenuButton* button = new BookmarkFolderButton( |
1131 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), this, false); | 1174 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), this, false); |
1132 button->SetIcon(GetGroupIcon()); | 1175 button->SetIcon(GetGroupIcon()); |
1133 button->SetContextMenuController(this); | 1176 button->SetContextMenuController(this); |
| 1177 button->SetListener(this, kOtherFolderButtonTag); |
1134 return button; | 1178 return button; |
1135 } | 1179 } |
1136 | 1180 |
1137 MenuButton* BookmarkBarView::CreateOverflowButton() { | 1181 MenuButton* BookmarkBarView::CreateOverflowButton() { |
1138 MenuButton* button = new MenuButton(std::wstring(), this, false); | 1182 MenuButton* button = new MenuButton(std::wstring(), this, false); |
1139 button->SetIcon(*ResourceBundle::GetSharedInstance(). | 1183 button->SetIcon(*ResourceBundle::GetSharedInstance(). |
1140 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS)); | 1184 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS)); |
1141 | 1185 |
1142 // The overflow button's image contains an arrow and therefore it is a | 1186 // The overflow button's image contains an arrow and therefore it is a |
1143 // direction sensitive image and we need to flip it if the UI layout is | 1187 // direction sensitive image and we need to flip it if the UI layout is |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 menu_runner_.reset(new MenuRunner(this, node, start_index)); | 1408 menu_runner_.reset(new MenuRunner(this, node, start_index)); |
1365 HWND parent_hwnd = GetViewContainer()->GetHWND(); | 1409 HWND parent_hwnd = GetViewContainer()->GetHWND(); |
1366 menu_runner_->RunMenuAt(parent_hwnd, | 1410 menu_runner_->RunMenuAt(parent_hwnd, |
1367 gfx::Rect(screen_loc.x, screen_loc.y, | 1411 gfx::Rect(screen_loc.x, screen_loc.y, |
1368 view->width(), bar_height), | 1412 view->width(), bar_height), |
1369 anchor_point, | 1413 anchor_point, |
1370 false); | 1414 false); |
1371 } | 1415 } |
1372 | 1416 |
1373 void BookmarkBarView::ButtonPressed(ChromeViews::BaseButton* sender) { | 1417 void BookmarkBarView::ButtonPressed(ChromeViews::BaseButton* sender) { |
1374 int index = GetChildIndex(sender); | 1418 BookmarkNode* node; |
1375 DCHECK(index != -1); | 1419 if (sender->GetTag() == kOtherFolderButtonTag) { |
1376 BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(index); | 1420 node = model_->other_node(); |
| 1421 } else { |
| 1422 int index = GetChildIndex(sender); |
| 1423 DCHECK(index != -1); |
| 1424 node = model_->GetBookmarkBarNode()->GetChild(index); |
| 1425 } |
1377 DCHECK(page_navigator_); | 1426 DCHECK(page_navigator_); |
1378 page_navigator_->OpenURL( | 1427 if (node->is_url()) { |
1379 node->GetURL(), | 1428 page_navigator_->OpenURL( |
1380 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()), | 1429 node->GetURL(), |
1381 PageTransition::AUTO_BOOKMARK); | 1430 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()), |
| 1431 PageTransition::AUTO_BOOKMARK); |
| 1432 } else { |
| 1433 BookmarkBarContextMenuController::OpenAll( |
| 1434 GetViewContainer()->GetHWND(), GetPageNavigator(), node, |
| 1435 event_utils::DispositionFromEventFlags(sender->mouse_event_flags())); |
| 1436 } |
1382 UserMetrics::RecordAction(L"ClickedBookmarkBarURLButton", profile_); | 1437 UserMetrics::RecordAction(L"ClickedBookmarkBarURLButton", profile_); |
1383 } | 1438 } |
1384 | 1439 |
1385 void BookmarkBarView::ShowContextMenu(View* source, | 1440 void BookmarkBarView::ShowContextMenu(View* source, |
1386 int x, | 1441 int x, |
1387 int y, | 1442 int y, |
1388 bool is_mouse_gesture) { | 1443 bool is_mouse_gesture) { |
1389 if (!model_->IsLoaded()) { | 1444 if (!model_->IsLoaded()) { |
1390 // Don't do anything if the model isn't loaded. | 1445 // Don't do anything if the model isn't loaded. |
1391 return; | 1446 return; |
(...skipping 17 matching lines...) Expand all Loading... |
1409 ChromeViews::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) { | 1464 ChromeViews::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) { |
1410 if (node->GetType() == history::StarredEntry::URL) { | 1465 if (node->GetType() == history::StarredEntry::URL) { |
1411 BookmarkButton* button = new BookmarkButton(node->GetURL(), | 1466 BookmarkButton* button = new BookmarkButton(node->GetURL(), |
1412 node->GetTitle(), | 1467 node->GetTitle(), |
1413 GetProfile()); | 1468 GetProfile()); |
1414 button->SetListener(this, 0); | 1469 button->SetListener(this, 0); |
1415 ConfigureButton(node, button); | 1470 ConfigureButton(node, button); |
1416 return button; | 1471 return button; |
1417 } else { | 1472 } else { |
1418 ChromeViews::MenuButton* button = | 1473 ChromeViews::MenuButton* button = |
1419 new ChromeViews::MenuButton(node->GetTitle(), this, false); | 1474 new BookmarkFolderButton(node->GetTitle(), this, false); |
1420 button->SetIcon(GetGroupIcon()); | 1475 button->SetIcon(GetGroupIcon()); |
| 1476 button->SetListener(this, 0); |
1421 ConfigureButton(node, button); | 1477 ConfigureButton(node, button); |
1422 return button; | 1478 return button; |
1423 } | 1479 } |
1424 } | 1480 } |
1425 | 1481 |
1426 void BookmarkBarView::ConfigureButton(BookmarkNode* node, | 1482 void BookmarkBarView::ConfigureButton(BookmarkNode* node, |
1427 ChromeViews::TextButton* button) { | 1483 ChromeViews::TextButton* button) { |
1428 button->SetText(node->GetTitle()); | 1484 button->SetText(node->GetTitle()); |
1429 button->ClearMaxTextSize(); | 1485 button->ClearMaxTextSize(); |
1430 button->SetContextMenuController(this); | 1486 button->SetContextMenuController(this); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 } | 1856 } |
1801 | 1857 |
1802 void BookmarkBarView::StopThrobbing(bool immediate) { | 1858 void BookmarkBarView::StopThrobbing(bool immediate) { |
1803 if (!throbbing_view_) | 1859 if (!throbbing_view_) |
1804 return; | 1860 return; |
1805 | 1861 |
1806 // If not immediate, cycle through 2 more complete cycles. | 1862 // If not immediate, cycle through 2 more complete cycles. |
1807 throbbing_view_->StartThrobbing(immediate ? 0 : 4); | 1863 throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
1808 throbbing_view_ = NULL; | 1864 throbbing_view_ = NULL; |
1809 } | 1865 } |
OLD | NEW |