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

Side by Side Diff: chrome/views/chrome_menu.cc

Issue 21354: Context menu for title bar doesn't appear... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/views/chrome_menu.h" 5 #include "chrome/views/chrome_menu.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <uxtheme.h> 8 #include <uxtheme.h>
9 #include <Vssym32.h> 9 #include <Vssym32.h>
10 10
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 static bool show_mnemonics; 118 static bool show_mnemonics;
119 119
120 using gfx::NativeTheme; 120 using gfx::NativeTheme;
121 121
122 namespace views { 122 namespace views {
123 123
124 namespace { 124 namespace {
125 125
126 // Returns the font menus are to use. 126 // Returns the font menus are to use.
127 ChromeFont GetMenuFont() { 127 ChromeFont GetMenuFont() {
128 » NONCLIENTMETRICS metrics; 128 NONCLIENTMETRICS metrics;
129 win_util::GetNonClientMetrics(&metrics); 129 win_util::GetNonClientMetrics(&metrics);
130 130
131 HFONT font = CreateFontIndirect(&metrics.lfMenuFont); 131 HFONT font = CreateFontIndirect(&metrics.lfMenuFont);
132 DLOG_ASSERT(font); 132 DLOG_ASSERT(font);
133 return ChromeFont::CreateFont(font); 133 return ChromeFont::CreateFont(font);
134 } 134 }
135 135
136 // Calculates all sizes that we can from the OS. 136 // Calculates all sizes that we can from the OS.
137 // 137 //
138 // This is invoked prior to Running a menu. 138 // This is invoked prior to Running a menu.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 208
209 // MenuScrollTask -------------------------------------------------------------- 209 // MenuScrollTask --------------------------------------------------------------
210 210
211 // MenuScrollTask is used when the SubmenuView does not all fit on screen and 211 // MenuScrollTask is used when the SubmenuView does not all fit on screen and
212 // the mouse is over the scroll up/down buttons. MenuScrollTask schedules 212 // the mouse is over the scroll up/down buttons. MenuScrollTask schedules
213 // itself with a RepeatingTimer. When Run is invoked MenuScrollTask scrolls 213 // itself with a RepeatingTimer. When Run is invoked MenuScrollTask scrolls
214 // appropriately. 214 // appropriately.
215 215
216 class MenuScrollTask { 216 class MenuScrollTask {
217 public: 217 public:
218 MenuScrollTask() : submenu_(NULL) { 218 MenuScrollTask() : submenu_(NULL) {
219 pixels_per_second_ = pref_menu_height * 20; 219 pixels_per_second_ = pref_menu_height * 20;
220 } 220 }
221 221
222 void Update(const MenuController::MenuPart& part) { 222 void Update(const MenuController::MenuPart& part) {
223 if (!part.is_scroll()) { 223 if (!part.is_scroll()) {
224 StopScrolling(); 224 StopScrolling();
225 return; 225 return;
226 } 226 }
227 DCHECK(part.submenu); 227 DCHECK(part.submenu);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 // Time we started scrolling at. 280 // Time we started scrolling at.
281 Time start_scroll_time_; 281 Time start_scroll_time_;
282 282
283 // How many pixels to scroll per second. 283 // How many pixels to scroll per second.
284 int pixels_per_second_; 284 int pixels_per_second_;
285 285
286 // Y-coordinate of submenu_view_ when scrolling started. 286 // Y-coordinate of submenu_view_ when scrolling started.
287 int start_y_; 287 int start_y_;
288 288
289 DISALLOW_EVIL_CONSTRUCTORS(MenuScrollTask); 289 DISALLOW_COPY_AND_ASSIGN(MenuScrollTask);
290 }; 290 };
291 291
292 // MenuScrollButton ------------------------------------------------------------ 292 // MenuScrollButton ------------------------------------------------------------
293 293
294 // MenuScrollButton is used for the scroll buttons when not all menu items fit 294 // MenuScrollButton is used for the scroll buttons when not all menu items fit
295 // on screen. MenuScrollButton forwards appropriate events to the 295 // on screen. MenuScrollButton forwards appropriate events to the
296 // MenuController. 296 // MenuController.
297 297
298 class MenuScrollButton : public View { 298 class MenuScrollButton : public View {
299 public: 299 public:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 private: 359 private:
360 // SubmenuView we were created for. 360 // SubmenuView we were created for.
361 SubmenuView* host_; 361 SubmenuView* host_;
362 362
363 // Direction of the button. 363 // Direction of the button.
364 bool is_up_; 364 bool is_up_;
365 365
366 // Preferred height. 366 // Preferred height.
367 int pref_height_; 367 int pref_height_;
368 368
369 DISALLOW_EVIL_CONSTRUCTORS(MenuScrollButton); 369 DISALLOW_COPY_AND_ASSIGN(MenuScrollButton);
370 }; 370 };
371 371
372 // MenuScrollView -------------------------------------------------------------- 372 // MenuScrollView --------------------------------------------------------------
373 373
374 // MenuScrollView is a viewport for the SubmenuView. It's reason to exist is so 374 // MenuScrollView is a viewport for the SubmenuView. It's reason to exist is so
375 // that ScrollRectToVisible works. 375 // that ScrollRectToVisible works.
376 // 376 //
377 // NOTE: It is possible to use ScrollView directly (after making it deal with 377 // NOTE: It is possible to use ScrollView directly (after making it deal with
378 // null scrollbars), but clicking on a child of ScrollView forces the window to 378 // null scrollbars), but clicking on a child of ScrollView forces the window to
379 // become active, which we don't want. As we really only need a fraction of 379 // become active, which we don't want. As we really only need a fraction of
(...skipping 16 matching lines...) Expand all
396 y = std::max(0, std::min(pref.height() - this->height(), y)); 396 y = std::max(0, std::min(pref.height() - this->height(), y));
397 child->SetY(-y); 397 child->SetY(-y);
398 } 398 }
399 399
400 // Returns the contents, which is the SubmenuView. 400 // Returns the contents, which is the SubmenuView.
401 View* GetContents() { 401 View* GetContents() {
402 return GetChildViewAt(0); 402 return GetChildViewAt(0);
403 } 403 }
404 404
405 private: 405 private:
406 DISALLOW_EVIL_CONSTRUCTORS(MenuScrollView); 406 DISALLOW_COPY_AND_ASSIGN(MenuScrollView);
407 }; 407 };
408 408
409 // MenuScrollViewContainer ----------------------------------------------------- 409 // MenuScrollViewContainer -----------------------------------------------------
410 410
411 // MenuScrollViewContainer contains the SubmenuView (through a MenuScrollView) 411 // MenuScrollViewContainer contains the SubmenuView (through a MenuScrollView)
412 // and two scroll buttons. The scroll buttons are only visible and enabled if 412 // and two scroll buttons. The scroll buttons are only visible and enabled if
413 // the preferred height of the SubmenuView is bigger than our bounds. 413 // the preferred height of the SubmenuView is bigger than our bounds.
414 class MenuScrollViewContainer : public View { 414 class MenuScrollViewContainer : public View {
415 public: 415 public:
416 explicit MenuScrollViewContainer(SubmenuView* content_view) { 416 explicit MenuScrollViewContainer(SubmenuView* content_view) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 481 }
482 482
483 private: 483 private:
484 // The scroll buttons. 484 // The scroll buttons.
485 View* scroll_up_button_; 485 View* scroll_up_button_;
486 View* scroll_down_button_; 486 View* scroll_down_button_;
487 487
488 // The scroll view. 488 // The scroll view.
489 MenuScrollView* scroll_view_; 489 MenuScrollView* scroll_view_;
490 490
491 DISALLOW_EVIL_CONSTRUCTORS(MenuScrollViewContainer); 491 DISALLOW_COPY_AND_ASSIGN(MenuScrollViewContainer);
492 }; 492 };
493 493
494 // MenuSeparator --------------------------------------------------------------- 494 // MenuSeparator ---------------------------------------------------------------
495 495
496 // Renders a separator. 496 // Renders a separator.
497 497
498 class MenuSeparator : public View { 498 class MenuSeparator : public View {
499 public: 499 public:
500 MenuSeparator() { 500 MenuSeparator() {
501 } 501 }
(...skipping 14 matching lines...) Expand all
516 start_x = gutter_bounds.left + gutter_width; 516 start_x = gutter_bounds.left + gutter_width;
517 start_y = 0; 517 start_y = 0;
518 } 518 }
519 RECT separator_bounds = { start_x, start_y, width(), height() }; 519 RECT separator_bounds = { start_x, start_y, width(), height() };
520 NativeTheme::instance()->PaintMenuSeparator(dc, MENU_POPUPSEPARATOR, 520 NativeTheme::instance()->PaintMenuSeparator(dc, MENU_POPUPSEPARATOR,
521 MPI_NORMAL, &separator_bounds); 521 MPI_NORMAL, &separator_bounds);
522 canvas->endPlatformPaint(); 522 canvas->endPlatformPaint();
523 } 523 }
524 524
525 gfx::Size GetPreferredSize() { 525 gfx::Size GetPreferredSize() {
526 return gfx::Size(10, // Just in case we're the only item in a menu. 526 return gfx::Size(10, // Just in case we're the only item in a menu.
527 separator_height); 527 separator_height);
528 } 528 }
529 529
530 private: 530 private:
531 DISALLOW_EVIL_CONSTRUCTORS(MenuSeparator); 531 DISALLOW_COPY_AND_ASSIGN(MenuSeparator);
532 }; 532 };
533 533
534 // MenuHostRootView ---------------------------------------------------------- 534 // MenuHostRootView ----------------------------------------------------------
535 535
536 // MenuHostRootView is the RootView of the window showing the menu. 536 // MenuHostRootView is the RootView of the window showing the menu.
537 // SubmenuView's scroll view is added as a child of MenuHostRootView. 537 // SubmenuView's scroll view is added as a child of MenuHostRootView.
538 // MenuHostRootView forwards relevant events to the MenuController. 538 // MenuHostRootView forwards relevant events to the MenuController.
539 // 539 //
540 // As all the menu items are owned by the root menu item, care must be taken 540 // As all the menu items are owned by the root menu item, care must be taken
541 // such that when MenuHostRootView is deleted it doesn't delete the menu items. 541 // such that when MenuHostRootView is deleted it doesn't delete the menu items.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 619
620 void SuspendEvents() { 620 void SuspendEvents() {
621 suspend_events_ = true; 621 suspend_events_ = true;
622 } 622 }
623 623
624 private: 624 private:
625 MenuController* GetMenuController() { 625 MenuController* GetMenuController() {
626 return submenu_->GetMenuItem()->GetMenuController(); 626 return submenu_->GetMenuItem()->GetMenuController();
627 } 627 }
628 628
629 /// The SubmenuView we contain. 629 // The SubmenuView we contain.
630 SubmenuView* submenu_; 630 SubmenuView* submenu_;
631 631
632 // Whether mouse dragged/released should be forwarded to the MenuController. 632 // Whether mouse dragged/released should be forwarded to the MenuController.
633 bool forward_drag_to_menu_controller_; 633 bool forward_drag_to_menu_controller_;
634 634
635 // Whether events are suspended. If true, no events are forwarded to the 635 // Whether events are suspended. If true, no events are forwarded to the
636 // MenuController. 636 // MenuController.
637 bool suspend_events_; 637 bool suspend_events_;
638 638
639 DISALLOW_EVIL_CONSTRUCTORS(MenuHostRootView); 639 DISALLOW_COPY_AND_ASSIGN(MenuHostRootView);
640 }; 640 };
641 641
642 // MenuHost ------------------------------------------------------------------ 642 // MenuHost ------------------------------------------------------------------
643 643
644 // MenuHost is the window responsible for showing a single menu. 644 // MenuHost is the window responsible for showing a single menu.
645 // 645 //
646 // Similar to MenuHostRootView, care must be taken such that when MenuHost is 646 // Similar to MenuHostRootView, care must be taken such that when MenuHost is
647 // deleted, it doesn't delete the menu items. MenuHost is closed via a 647 // deleted, it doesn't delete the menu items. MenuHost is closed via a
648 // DelayedClosed, which avoids timing issues with deleting the window while 648 // DelayedClosed, which avoids timing issues with deleting the window while
649 // capture or events are directed at it. 649 // capture or events are directed at it.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 private: 750 private:
751 // If true, we've been closed. 751 // If true, we've been closed.
752 bool closed_; 752 bool closed_;
753 753
754 // If true, we own the capture and need to release it. 754 // If true, we own the capture and need to release it.
755 bool owns_capture_; 755 bool owns_capture_;
756 756
757 // The view we contain. 757 // The view we contain.
758 SubmenuView* submenu_; 758 SubmenuView* submenu_;
759 759
760 DISALLOW_EVIL_CONSTRUCTORS(MenuHost); 760 DISALLOW_COPY_AND_ASSIGN(MenuHost);
761 }; 761 };
762 762
763 // EmptyMenuMenuItem --------------------------------------------------------- 763 // EmptyMenuMenuItem ---------------------------------------------------------
764 764
765 // EmptyMenuMenuItem is used when a menu has no menu items. EmptyMenuMenuItem 765 // EmptyMenuMenuItem is used when a menu has no menu items. EmptyMenuMenuItem
766 // is itself a MenuItemView, but it uses a different ID so that it isn't 766 // is itself a MenuItemView, but it uses a different ID so that it isn't
767 // identified as a MenuItemView. 767 // identified as a MenuItemView.
768 768
769 class EmptyMenuMenuItem : public MenuItemView { 769 class EmptyMenuMenuItem : public MenuItemView {
770 public: 770 public:
771 // ID used for EmptyMenuMenuItem. 771 // ID used for EmptyMenuMenuItem.
772 static const int kEmptyMenuItemViewID; 772 static const int kEmptyMenuItemViewID;
773 773
774 EmptyMenuMenuItem(MenuItemView* parent) : MenuItemView(parent, 0, NORMAL) { 774 EmptyMenuMenuItem(MenuItemView* parent) : MenuItemView(parent, 0, NORMAL) {
775 SetTitle(l10n_util::GetString(IDS_MENU_EMPTY_SUBMENU)); 775 SetTitle(l10n_util::GetString(IDS_MENU_EMPTY_SUBMENU));
776 // Set this so that we're not identified as a normal menu item. 776 // Set this so that we're not identified as a normal menu item.
777 SetID(kEmptyMenuItemViewID); 777 SetID(kEmptyMenuItemViewID);
778 SetEnabled(false); 778 SetEnabled(false);
779 } 779 }
780 780
781 private: 781 private:
782 DISALLOW_EVIL_CONSTRUCTORS(EmptyMenuMenuItem); 782 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem);
783 }; 783 };
784 784
785 // static 785 // static
786 const int EmptyMenuMenuItem::kEmptyMenuItemViewID = 786 const int EmptyMenuMenuItem::kEmptyMenuItemViewID =
787 MenuItemView::kMenuItemViewID + 1; 787 MenuItemView::kMenuItemViewID + 1;
788 788
789 } // namespace 789 } // namespace
790 790
791 // SubmenuView --------------------------------------------------------------- 791 // SubmenuView ---------------------------------------------------------------
792 792
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 press_loc.y(), data); 1813 press_loc.y(), data);
1814 1814
1815 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); 1815 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource);
1816 int drag_ops = item->GetDelegate()->GetDragOperations(item); 1816 int drag_ops = item->GetDelegate()->GetDragOperations(item);
1817 DWORD effects; 1817 DWORD effects;
1818 StopScrolling(); 1818 StopScrolling();
1819 DoDragDrop(data, drag_source, 1819 DoDragDrop(data, drag_source,
1820 DragDropTypes::DragOperationToDropEffect(drag_ops), 1820 DragDropTypes::DragOperationToDropEffect(drag_ops),
1821 &effects); 1821 &effects);
1822 if (GetActiveInstance() == this) { 1822 if (GetActiveInstance() == this) {
1823 if (showing_ ) { 1823 if (showing_) {
1824 // We're still showing, close all menus. 1824 // We're still showing, close all menus.
1825 CloseAllNestedMenus(); 1825 CloseAllNestedMenus();
1826 Cancel(true); 1826 Cancel(true);
1827 } // else case, drop was on us. 1827 } // else case, drop was on us.
1828 } // else case, someone canceled us, don't do anything 1828 } // else case, someone canceled us, don't do anything
1829 } 1829 }
1830 return; 1830 return;
1831 } 1831 }
1832 if (part.type == MenuPart::MENU_ITEM) { 1832 if (part.type == MenuPart::MENU_ITEM) {
1833 if (!part.menu) 1833 if (!part.menu)
1834 part.menu = source->GetMenuItem(); 1834 part.menu = source->GetMenuItem();
1835 SetSelection(part.menu ? part.menu : state_.item, true, false); 1835 SetSelection(part.menu ? part.menu : state_.item, true, false);
1836 } 1836 }
1837 any_menu_contains_mouse_ = (part.type == MenuPart::MENU_ITEM); 1837 any_menu_contains_mouse_ = (part.type == MenuPart::MENU_ITEM);
1838 } 1838 }
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2589 void MenuController::IncrementSelection(int delta) { 2589 void MenuController::IncrementSelection(int delta) {
2590 MenuItemView* item = pending_state_.item; 2590 MenuItemView* item = pending_state_.item;
2591 DCHECK(item); 2591 DCHECK(item);
2592 if (pending_state_.submenu_open && item->HasSubmenu() && 2592 if (pending_state_.submenu_open && item->HasSubmenu() &&
2593 item->GetSubmenu()->IsShowing()) { 2593 item->GetSubmenu()->IsShowing()) {
2594 // A menu is selected and open, but none of its children are selected, 2594 // A menu is selected and open, but none of its children are selected,
2595 // select the first menu item. 2595 // select the first menu item.
2596 if (item->GetSubmenu()->GetMenuItemCount()) { 2596 if (item->GetSubmenu()->GetMenuItemCount()) {
2597 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), false, false); 2597 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), false, false);
2598 ScrollToVisible(item->GetSubmenu()->GetMenuItemAt(0)); 2598 ScrollToVisible(item->GetSubmenu()->GetMenuItemAt(0));
2599 return; // return so else case can fall through. 2599 return; // return so else case can fall through.
2600 } 2600 }
2601 } 2601 }
2602 if (item->GetParentMenuItem()) { 2602 if (item->GetParentMenuItem()) {
2603 MenuItemView* parent = item->GetParentMenuItem(); 2603 MenuItemView* parent = item->GetParentMenuItem();
2604 int parent_count = parent->GetSubmenu()->GetMenuItemCount(); 2604 int parent_count = parent->GetSubmenu()->GetMenuItemCount();
2605 if (parent_count > 1) { 2605 if (parent_count > 1) {
2606 for (int i = 0; i < parent_count; ++i) { 2606 for (int i = 0; i < parent_count; ++i) {
2607 if (parent->GetSubmenu()->GetMenuItemAt(i) == item) { 2607 if (parent->GetSubmenu()->GetMenuItemAt(i) == item) {
2608 int next_index = (i + delta + parent_count) % parent_count; 2608 int next_index = (i + delta + parent_count) % parent_count;
2609 ScrollToVisible(parent->GetSubmenu()->GetMenuItemAt(next_index)); 2609 ScrollToVisible(parent->GetSubmenu()->GetMenuItemAt(next_index));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2757 else if (event.IsRightMouseButton()) 2757 else if (event.IsRightMouseButton())
2758 event_type = in_client_area ? WM_RBUTTONDOWN : WM_NCRBUTTONDOWN; 2758 event_type = in_client_area ? WM_RBUTTONDOWN : WM_NCRBUTTONDOWN;
2759 else 2759 else
2760 event_type = 0; // Unknown mouse press. 2760 event_type = 0; // Unknown mouse press.
2761 2761
2762 if (event_type) { 2762 if (event_type) {
2763 if (in_client_area) { 2763 if (in_client_area) {
2764 PostMessage(window, event_type, event.GetWindowsFlags(), 2764 PostMessage(window, event_type, event.GetWindowsFlags(),
2765 MAKELPARAM(window_x, window_y)); 2765 MAKELPARAM(window_x, window_y));
2766 } else { 2766 } else {
2767 PostMessage(window, WM_NCLBUTTONDOWN, nc_hit_result, 2767 PostMessage(window, event_type, nc_hit_result,
2768 MAKELPARAM(window_x, window_y)); 2768 MAKELPARAM(screen_loc.x(), screen_loc.y()));
2769 } 2769 }
2770 } 2770 }
2771 } 2771 }
2772 } 2772 }
2773 2773
2774 void MenuController::SetDropMenuItem( 2774 void MenuController::SetDropMenuItem(
2775 MenuItemView* new_target, 2775 MenuItemView* new_target,
2776 MenuDelegate::DropPosition new_position) { 2776 MenuDelegate::DropPosition new_position) {
2777 if (new_target == drop_target_ && new_position == drop_position_) 2777 if (new_target == drop_target_ && new_position == drop_position_)
2778 return; 2778 return;
(...skipping 17 matching lines...) Expand all
2796 if (!scroll_task_.get()) 2796 if (!scroll_task_.get())
2797 scroll_task_.reset(new MenuScrollTask()); 2797 scroll_task_.reset(new MenuScrollTask());
2798 scroll_task_->Update(part); 2798 scroll_task_->Update(part);
2799 } 2799 }
2800 2800
2801 void MenuController::StopScrolling() { 2801 void MenuController::StopScrolling() {
2802 scroll_task_.reset(NULL); 2802 scroll_task_.reset(NULL);
2803 } 2803 }
2804 2804
2805 } // namespace views 2805 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698