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

Side by Side Diff: ui/views/controls/combobox/combobox.cc

Issue 2394123002: Views: Expose an on_closed callback via the MenuRunner constructor. (Closed)
Patch Set: default arg Created 4 years, 2 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
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/menu/menu_runner.h » ('j') | 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) 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/combobox/combobox.h" 5 #include "ui/views/controls/combobox/combobox.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "ui/resources/grit/ui_resources.h" 30 #include "ui/resources/grit/ui_resources.h"
31 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 31 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
32 #include "ui/views/animation/ink_drop_highlight.h" 32 #include "ui/views/animation/ink_drop_highlight.h"
33 #include "ui/views/background.h" 33 #include "ui/views/background.h"
34 #include "ui/views/controls/button/custom_button.h" 34 #include "ui/views/controls/button/custom_button.h"
35 #include "ui/views/controls/button/label_button.h" 35 #include "ui/views/controls/button/label_button.h"
36 #include "ui/views/controls/combobox/combobox_listener.h" 36 #include "ui/views/controls/combobox/combobox_listener.h"
37 #include "ui/views/controls/focus_ring.h" 37 #include "ui/views/controls/focus_ring.h"
38 #include "ui/views/controls/focusable_border.h" 38 #include "ui/views/controls/focusable_border.h"
39 #include "ui/views/controls/menu/menu_config.h" 39 #include "ui/views/controls/menu/menu_config.h"
40 #include "ui/views/controls/menu/menu_model_adapter.h"
41 #include "ui/views/controls/menu/menu_runner.h" 40 #include "ui/views/controls/menu/menu_runner.h"
42 #include "ui/views/controls/prefix_selector.h" 41 #include "ui/views/controls/prefix_selector.h"
43 #include "ui/views/controls/textfield/textfield.h" 42 #include "ui/views/controls/textfield/textfield.h"
44 #include "ui/views/mouse_constants.h" 43 #include "ui/views/mouse_constants.h"
45 #include "ui/views/painter.h" 44 #include "ui/views/painter.h"
46 #include "ui/views/resources/grit/views_resources.h" 45 #include "ui/views/resources/grit/views_resources.h"
47 #include "ui/views/style/platform_style.h" 46 #include "ui/views/style/platform_style.h"
48 #include "ui/views/widget/widget.h" 47 #include "ui/views/widget/widget.h"
49 48
50 namespace views { 49 namespace views {
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 if (arrow_button_) { 915 if (arrow_button_) {
917 original_state = arrow_button_->state(); 916 original_state = arrow_button_->state();
918 arrow_button_->SetState(Button::STATE_PRESSED); 917 arrow_button_->SetState(Button::STATE_PRESSED);
919 } 918 }
920 MenuAnchorPosition anchor_position = 919 MenuAnchorPosition anchor_position =
921 style_ == STYLE_ACTION ? MENU_ANCHOR_TOPRIGHT : MENU_ANCHOR_TOPLEFT; 920 style_ == STYLE_ACTION ? MENU_ANCHOR_TOPRIGHT : MENU_ANCHOR_TOPLEFT;
922 921
923 // Allow |menu_runner_| to be set by the testing API, but if this method is 922 // Allow |menu_runner_| to be set by the testing API, but if this method is
924 // ever invoked recursively, ensure the old menu is closed. 923 // ever invoked recursively, ensure the old menu is closed.
925 if (!menu_runner_ || menu_runner_->IsRunning()) { 924 if (!menu_runner_ || menu_runner_->IsRunning()) {
926 menu_model_adapter_.reset(new MenuModelAdapter( 925 menu_runner_.reset(new MenuRunner(
927 menu_model_.get(), base::Bind(&Combobox::OnMenuClosed, 926 menu_model_.get(), MenuRunner::COMBOBOX | MenuRunner::ASYNC,
928 base::Unretained(this), original_state))); 927 base::Bind(&Combobox::OnMenuClosed, base::Unretained(this),
929 menu_runner_.reset( 928 original_state)));
930 new MenuRunner(menu_model_adapter_->CreateMenu(),
931 MenuRunner::COMBOBOX | MenuRunner::ASYNC));
932 } 929 }
933 menu_runner_->RunMenuAt(GetWidget(), nullptr, bounds, anchor_position, 930 menu_runner_->RunMenuAt(GetWidget(), nullptr, bounds, anchor_position,
934 source_type); 931 source_type);
935 } 932 }
936 933
937 void Combobox::OnMenuClosed(Button::ButtonState original_button_state) { 934 void Combobox::OnMenuClosed(Button::ButtonState original_button_state) {
938 menu_runner_.reset(); 935 menu_runner_.reset();
939 menu_model_adapter_.reset();
940 if (arrow_button_) 936 if (arrow_button_)
941 arrow_button_->SetState(original_button_state); 937 arrow_button_->SetState(original_button_state);
942 closed_time_ = base::Time::Now(); 938 closed_time_ = base::Time::Now();
943 939
944 // Need to explicitly clear mouse handler so that events get sent 940 // Need to explicitly clear mouse handler so that events get sent
945 // properly after the menu finishes running. If we don't do this, then 941 // properly after the menu finishes running. If we don't do this, then
946 // the first click to other parts of the UI is eaten. 942 // the first click to other parts of the UI is eaten.
947 SetMouseHandler(NULL); 943 SetMouseHandler(NULL);
948 } 944 }
949 945
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 const int kMdPaddingWidth = 8; 986 const int kMdPaddingWidth = 8;
991 int arrow_pad = UseMd() ? kMdPaddingWidth 987 int arrow_pad = UseMd() ? kMdPaddingWidth
992 : PlatformStyle::kComboboxNormalArrowPadding; 988 : PlatformStyle::kComboboxNormalArrowPadding;
993 int padding = style_ == STYLE_NORMAL 989 int padding = style_ == STYLE_NORMAL
994 ? arrow_pad * 2 990 ? arrow_pad * 2
995 : kActionLeftPadding + kActionRightPadding; 991 : kActionLeftPadding + kActionRightPadding;
996 return ArrowSize().width() + padding; 992 return ArrowSize().width() + padding;
997 } 993 }
998 994
999 } // namespace views 995 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/menu/menu_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698