OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/controls/button/multi_target_button.h" | |
6 | |
7 #include "grit/ui_resources.h" | |
8 #include "ui/base/models/menu_model.h" | |
9 #include "ui/base/resource/resource_bundle.h" | |
10 #include "ui/views/controls/button/label_button.h" | |
11 #include "ui/views/controls/button/label_button_border.h" | |
12 #include "ui/views/controls/button/menu_button.h" | |
13 #include "ui/views/controls/menu/menu_runner.h" | |
14 #include "ui/views/layout/box_layout.h" | |
15 | |
16 namespace views { | |
17 | |
18 MultiTargetButton::MultiTargetButton(ui::MenuModel* menu_model) | |
19 : menu_model_(menu_model) { | |
20 SetLayoutManager( | |
21 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -4)); | |
hajimehoshi
2013/11/05 10:10:26
-4 is to remove the space between two buttons. Wou
| |
22 | |
23 button_ = new views::LabelButton(this, menu_model->GetLabelAt(0)); | |
sky
2013/11/05 16:29:37
Using two buttons side by side is problematic beca
| |
24 button_->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); | |
25 AddChildView(button_); | |
26 | |
27 drop_arrow_button_ = new MenuButton(NULL, string16(), this, true); | |
28 drop_arrow_button_->set_focusable(true); | |
29 drop_arrow_button_->set_border( | |
30 new views::LabelButtonBorder(Button::STYLE_BUTTON)); | |
31 AddChildView(drop_arrow_button_); | |
32 } | |
33 | |
34 MultiTargetButton::~MultiTargetButton() { | |
35 } | |
36 | |
37 void MultiTargetButton::ButtonPressed(Button* sender, const ui::Event& event) { | |
38 menu_model_->ActivatedAt(0); | |
39 } | |
40 | |
41 void MultiTargetButton::OnMenuButtonClicked( | |
42 View* source, const gfx::Point& point) { | |
43 DCHECK_EQ(drop_arrow_button_, source); | |
44 menu_runner_.reset(new MenuRunner(menu_model_)); | |
45 ignore_result(menu_runner_->RunMenuAt(source->GetWidget(), drop_arrow_button_, | |
46 gfx::Rect(point, gfx::Size()), | |
47 MenuItemView::TOPRIGHT, | |
48 ui::MenuSourceType::MENU_SOURCE_MOUSE, | |
49 MenuRunner::HAS_MNEMONICS)); | |
50 } | |
51 | |
52 } // namespace views | |
OLD | NEW |