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 "views/controls/button/button_dropdown.h" | 5 #include "views/controls/button/button_dropdown.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "grit/app_strings.h" | 10 #include "grit/app_strings.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 SetState(BS_PUSHED); | 74 SetState(BS_PUSHED); |
75 PaintNow(); | 75 PaintNow(); |
76 ShowDropDownMenu(GetWidget()->GetNativeView()); | 76 ShowDropDownMenu(GetWidget()->GetNativeView()); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 bool ButtonDropDown::OnMouseDragged(const MouseEvent& e) { | 80 bool ButtonDropDown::OnMouseDragged(const MouseEvent& e) { |
81 bool result = ImageButton::OnMouseDragged(e); | 81 bool result = ImageButton::OnMouseDragged(e); |
82 | 82 |
83 if (!show_menu_factory_.empty()) { | 83 if (!show_menu_factory_.empty()) { |
84 // SM_CYDRAG is a pixel value for minimum dragging distance before operation | |
85 // counts as a drag, and not just as a click and accidental move of a mouse. | |
86 // See http://msdn2.microsoft.com/en-us/library/ms724385.aspx for details. | |
87 int dragging_threshold = GetSystemMetrics(SM_CYDRAG); | |
88 | |
89 // If the mouse is dragged to a y position lower than where it was when | 84 // If the mouse is dragged to a y position lower than where it was when |
90 // clicked then we should not wait for the menu to appear but show | 85 // clicked then we should not wait for the menu to appear but show |
91 // it immediately. | 86 // it immediately. |
92 if (e.y() > y_position_on_lbuttondown_ + dragging_threshold) { | 87 if (e.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) { |
93 show_menu_factory_.RevokeAll(); | 88 show_menu_factory_.RevokeAll(); |
94 ShowDropDownMenu(GetWidget()->GetNativeView()); | 89 ShowDropDownMenu(GetWidget()->GetNativeView()); |
95 } | 90 } |
96 } | 91 } |
97 | 92 |
98 return result; | 93 return result; |
99 } | 94 } |
100 | 95 |
101 //////////////////////////////////////////////////////////////////////////////// | 96 //////////////////////////////////////////////////////////////////////////////// |
102 // | 97 // |
(...skipping 23 matching lines...) Expand all Loading... |
126 menu_position.Offset(0, lb.height() - 1); | 121 menu_position.Offset(0, lb.height() - 1); |
127 if (UILayoutIsRightToLeft()) | 122 if (UILayoutIsRightToLeft()) |
128 menu_position.Offset(lb.width() - 1, 0); | 123 menu_position.Offset(lb.width() - 1, 0); |
129 | 124 |
130 Menu::AnchorPoint anchor = Menu::TOPLEFT; | 125 Menu::AnchorPoint anchor = Menu::TOPLEFT; |
131 if (UILayoutIsRightToLeft()) | 126 if (UILayoutIsRightToLeft()) |
132 anchor = Menu::TOPRIGHT; | 127 anchor = Menu::TOPRIGHT; |
133 | 128 |
134 View::ConvertPointToScreen(this, &menu_position); | 129 View::ConvertPointToScreen(this, &menu_position); |
135 | 130 |
| 131 #if defined(OS_WIN) |
136 int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN); | 132 int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN); |
| 133 #else |
| 134 int left_bound = 0; |
| 135 NOTIMPLEMENTED(); |
| 136 #endif |
137 if (menu_position.x() < left_bound) | 137 if (menu_position.x() < left_bound) |
138 menu_position.set_x(left_bound); | 138 menu_position.set_x(left_bound); |
139 | 139 |
140 scoped_ptr<Menu> menu(Menu::Create(menu_delegate_, anchor, window)); | 140 scoped_ptr<Menu> menu(Menu::Create(menu_delegate_, anchor, window)); |
141 | 141 |
142 // ID's for AppendMenu is 1-based because RunMenu will ignore the user | 142 // ID's for AppendMenu is 1-based because RunMenu will ignore the user |
143 // selection if id=0 is selected (0 = NO-OP) so we add 1 here and subtract 1 | 143 // selection if id=0 is selected (0 = NO-OP) so we add 1 here and subtract 1 |
144 // in the handlers above to get the actual index | 144 // in the handlers above to get the actual index |
145 int item_count = menu_delegate_->GetItemCount(); | 145 int item_count = menu_delegate_->GetItemCount(); |
146 for (int i = 0; i < item_count; i++) { | 146 for (int i = 0; i < item_count; i++) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 184 } |
185 | 185 |
186 bool ButtonDropDown::GetAccessibleState(AccessibilityTypes::State* state) { | 186 bool ButtonDropDown::GetAccessibleState(AccessibilityTypes::State* state) { |
187 DCHECK(state); | 187 DCHECK(state); |
188 | 188 |
189 *state = AccessibilityTypes::STATE_HASPOPUP; | 189 *state = AccessibilityTypes::STATE_HASPOPUP; |
190 return true; | 190 return true; |
191 } | 191 } |
192 | 192 |
193 } // namespace views | 193 } // namespace views |
OLD | NEW |