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/menu/menu_runner.h" | 5 #include "ui/views/controls/menu/menu_runner.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "ui/views/controls/button/menu_button.h" | 10 #include "ui/views/controls/button/menu_button.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 310 } |
311 | 311 |
312 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, | 312 MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent, |
313 MenuButton* button, | 313 MenuButton* button, |
314 const gfx::Rect& bounds, | 314 const gfx::Rect& bounds, |
315 MenuItemView::AnchorPosition anchor, | 315 MenuItemView::AnchorPosition anchor, |
316 int32 types) { | 316 int32 types) { |
317 // The parent of the nested menu will have created a DisplayChangeListener, so | 317 // The parent of the nested menu will have created a DisplayChangeListener, so |
318 // we avoid creating a DisplayChangeListener if nested. Drop menus are | 318 // we avoid creating a DisplayChangeListener if nested. Drop menus are |
319 // transient, so we don't cancel in that case. | 319 // transient, so we don't cancel in that case. |
320 if ((types & (IS_NESTED | FOR_DROP)) == 0) { | 320 if ((types & (IS_NESTED | FOR_DROP)) == 0 && parent) { |
321 display_change_listener_.reset( | 321 display_change_listener_.reset( |
322 internal::DisplayChangeListener::Create(parent, this)); | 322 internal::DisplayChangeListener::Create(parent, this)); |
323 } | 323 } |
324 if ((types & MenuRunner::CONTEXT_MENU) && | 324 if ((types & MenuRunner::CONTEXT_MENU) && |
325 parent && | 325 parent && |
326 parent->GetCurrentEvent() && | 326 parent->GetCurrentEvent() && |
327 !MenuItemView::IsBubble(anchor)) | 327 !MenuItemView::IsBubble(anchor)) |
328 anchor = parent->GetCurrentEvent()->IsGestureEvent() ? | 328 anchor = parent->GetCurrentEvent()->IsGestureEvent() ? |
329 MenuItemView::BOTTOMCENTER : MenuItemView::TOPLEFT; | 329 MenuItemView::BOTTOMCENTER : MenuItemView::TOPLEFT; |
330 | 330 |
331 return holder_->RunMenuAt(parent, button, bounds, anchor, types); | 331 return holder_->RunMenuAt(parent, button, bounds, anchor, types); |
332 } | 332 } |
333 | 333 |
334 bool MenuRunner::IsRunning() const { | 334 bool MenuRunner::IsRunning() const { |
335 return holder_->running(); | 335 return holder_->running(); |
336 } | 336 } |
337 | 337 |
338 void MenuRunner::Cancel() { | 338 void MenuRunner::Cancel() { |
339 holder_->Cancel(); | 339 holder_->Cancel(); |
340 } | 340 } |
341 | 341 |
342 } // namespace views | 342 } // namespace views |
OLD | NEW |