Chromium Code Reviews| 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 "ui/views/controls/button/menu_button.h" | 5 #include "ui/views/controls/button/menu_button.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
| 10 #include "ui/base/accessibility/accessible_view_state.h" | 10 #include "ui/base/accessibility/accessible_view_state.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 SetState(STATE_NORMAL); | 126 SetState(STATE_NORMAL); |
| 127 | 127 |
| 128 // We must return false here so that the RootView does not get stuck | 128 // We must return false here so that the RootView does not get stuck |
| 129 // sending all mouse pressed events to us instead of the appropriate | 129 // sending all mouse pressed events to us instead of the appropriate |
| 130 // target. | 130 // target. |
| 131 return false; | 131 return false; |
| 132 } | 132 } |
| 133 return true; | 133 return true; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) { | |
|
sky
2013/10/03 23:23:11
In general smaller patches are preferable. They ma
noms (inactive)
2013/10/07 21:18:15
Done.
| |
| 137 const gfx::Insets insets = GetInsets(); | |
| 138 | |
| 139 // We can not use the views' mirroring infrastructure for mirroring a | |
| 140 // MenuButton control (see TextButton::OnPaint() for a detailed explanation | |
| 141 // regarding why we can not flip the canvas). Therefore, we need to | |
| 142 // manually mirror the position of the down arrow. | |
| 143 gfx::Rect arrow_bounds(width() - insets.right() - | |
| 144 menu_marker_->width() - kMenuMarkerPaddingRight, | |
| 145 height() / 2 - menu_marker_->height() / 2, | |
| 146 menu_marker_->width(), | |
| 147 menu_marker_->height()); | |
| 148 arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds)); | |
| 149 canvas->DrawImageInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y()); | |
| 150 } | |
| 151 | |
| 136 void MenuButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 152 void MenuButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 137 TextButton::PaintButton(canvas, mode); | 153 TextButton::PaintButton(canvas, mode); |
| 138 | 154 |
| 139 if (show_menu_marker_) { | 155 if (show_menu_marker_) |
| 140 gfx::Insets insets = GetInsets(); | 156 PaintMenuMarker(canvas); |
| 141 | |
| 142 // We can not use the views' mirroring infrastructure for mirroring a | |
| 143 // MenuButton control (see TextButton::OnPaint() for a detailed explanation | |
| 144 // regarding why we can not flip the canvas). Therefore, we need to | |
| 145 // manually mirror the position of the down arrow. | |
| 146 gfx::Rect arrow_bounds(width() - insets.right() - | |
| 147 menu_marker_->width() - kMenuMarkerPaddingRight, | |
| 148 height() / 2 - menu_marker_->height() / 2, | |
| 149 menu_marker_->width(), | |
| 150 menu_marker_->height()); | |
| 151 arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds)); | |
| 152 canvas->DrawImageInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y()); | |
| 153 } | |
| 154 } | 157 } |
| 155 | 158 |
| 156 //////////////////////////////////////////////////////////////////////////////// | 159 //////////////////////////////////////////////////////////////////////////////// |
| 157 // | 160 // |
| 158 // MenuButton - Events | 161 // MenuButton - Events |
| 159 // | 162 // |
| 160 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
| 161 | 164 |
| 162 gfx::Size MenuButton::GetPreferredSize() { | 165 gfx::Size MenuButton::GetPreferredSize() { |
| 163 gfx::Size prefsize = TextButton::GetPreferredSize(); | 166 gfx::Size prefsize = TextButton::GetPreferredSize(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 if (!GetWidget()) { | 271 if (!GetWidget()) { |
| 269 NOTREACHED(); | 272 NOTREACHED(); |
| 270 return 0; | 273 return 0; |
| 271 } | 274 } |
| 272 | 275 |
| 273 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 276 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
| 274 return monitor_bounds.right() - 1; | 277 return monitor_bounds.right() - 1; |
| 275 } | 278 } |
| 276 | 279 |
| 277 } // namespace views | 280 } // namespace views |
| OLD | NEW |