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

Side by Side Diff: chrome/browser/ui/views/intent_picker_bubble_view.cc

Issue 2229943003: Reusing Ok/Cancel buttons for intent picker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing hovering color, modifying the test so it only access the minimum necessary info Created 4 years, 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/views/intent_picker_bubble_view.h" 5 #include "chrome/browser/ui/views/intent_picker_bubble_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/browser_finder.h" 11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/views/frame/browser_view.h" 12 #include "chrome/browser/ui/views/frame/browser_view.h"
13 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 13 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
14 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/navigation_handle.h" 15 #include "content/public/browser/navigation_handle.h"
16 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/material_design/material_design_controller.h"
18 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/views/animation/ink_drop_highlight.h"
19 #include "ui/views/border.h" 21 #include "ui/views/border.h"
20 #include "ui/views/controls/button/image_button.h" 22 #include "ui/views/controls/button/image_button.h"
21 #include "ui/views/controls/scroll_view.h" 23 #include "ui/views/controls/scroll_view.h"
22 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" 24 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
23 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
24 #include "ui/views/layout/grid_layout.h" 26 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/window/dialog_client_view.h" 27 #include "ui/views/window/dialog_client_view.h"
26 28
27 namespace { 29 namespace {
28 30
29 // Using |kMaxAppResults| as a measure of how many apps we want to show. 31 // Using |kMaxAppResults| as a measure of how many apps we want to show.
30 constexpr size_t kMaxAppResults = arc::ArcNavigationThrottle::kMaxAppResults; 32 constexpr size_t kMaxAppResults = arc::ArcNavigationThrottle::kMaxAppResults;
31 // Main components sizes 33 // Main components sizes
32 constexpr int kRowHeight = 40; 34 constexpr int kRowHeight = 40;
33 constexpr int kMaxWidth = 320; 35 constexpr int kMaxWidth = 320;
34 constexpr int kHeaderHeight = 60;
35 constexpr int kFooterHeight = 68;
36 // Inter components padding 36 // Inter components padding
37 constexpr int kButtonSeparation = 8;
38 constexpr int kLabelImageSeparation = 12; 37 constexpr int kLabelImageSeparation = 12;
39 38
40 // UI position wrt the Top Container 39 // UI position wrt the Top Container
41 constexpr int kTopContainerMerge = 3; 40 constexpr int kTopContainerMerge = 3;
42 constexpr size_t kAppTagNoneSelected = static_cast<size_t>(-1); 41 constexpr size_t kAppTagNoneSelected = static_cast<size_t>(-1);
43 42
44 // Arbitrary negative values to use as tags on the |always_button_| and 43 } // namespace
45 // |just_once_button_|. These are negative to differentiate from the app's tags
46 // which are always >= 0.
47 enum class Option : int { ALWAYS = -2, JUST_ONCE };
48 44
49 } // namespace 45 // IntentPickerMenuButton -----------------------------------------------------
46
47 // This is a convenience class for the buttons on the intent picker so we can
48 // manipulate the internal hovering behavior.
49
50 class IntentPickerMenuButton : public views::LabelButton {
Evan Stade 2016/08/18 05:45:41 I don't believe this class is necessary. You could
djacobo_ 2016/08/24 22:18:35 Hmm, that is true for all but SetInkDropMode(), it
Evan Stade 2016/08/26 22:44:23 I don't know if there's a good reason for SetInkDr
bruthig 2016/08/30 19:16:36 It should be ok to promote InkDropHostView::SetInk
djacobo_ 2016/09/06 23:21:23 Done, change here https://codereview.chromium.org/
bruthig 2016/09/07 14:58:43 Is this needed anymore?
djacobo_ 2016/09/08 00:10:30 Not really since I can already access SetInkDropMo
bruthig 2016/09/08 15:13:12 Ok, let's abandon that other change then.
djacobo_ 2016/09/08 21:27:06 Done.
51 public:
52 IntentPickerMenuButton(views::ButtonListener* listener,
53 const base::string16& title)
54 : LabelButton(listener, title) {
55 SetHorizontalAlignment(gfx::ALIGN_LEFT);
56 SetFocusBehavior(View::FocusBehavior::ALWAYS);
57 SetImageLabelSpacing(kLabelImageSeparation);
58 if (ui::MaterialDesignController::IsModeMaterial()) {
Evan Stade 2016/08/18 05:45:41 this isn't a useful check because it always return
djacobo_ 2016/08/24 22:18:35 I am removing this whole inner-class, done.
59 SetInkDropMode(InkDropMode::ON);
60 set_has_ink_drop_action_on_click(true);
61 }
62 }
63
64 SkColor GetInkDropBaseColor() const override { return SK_ColorBLACK; }
65
66 private:
67 DISALLOW_COPY_AND_ASSIGN(IntentPickerMenuButton);
68 };
50 69
51 // static 70 // static
52 void IntentPickerBubbleView::ShowBubble( 71 void IntentPickerBubbleView::ShowBubble(
53 content::NavigationHandle* handle, 72 content::NavigationHandle* handle,
54 const std::vector<NameAndIcon>& app_info, 73 const std::vector<NameAndIcon>& app_info,
55 const ThrottleCallback& throttle_cb) { 74 const ThrottleCallback& throttle_cb) {
56 Browser* browser = 75 Browser* browser =
57 chrome::FindBrowserWithWebContents(handle->GetWebContents()); 76 chrome::FindBrowserWithWebContents(handle->GetWebContents());
58 if (!browser) { 77 if (!browser) {
59 throttle_cb.Run(kAppTagNoneSelected, 78 throttle_cb.Run(kAppTagNoneSelected,
Evan Stade 2016/08/18 05:45:41 seems like these two blocks could/should be combin
djacobo_ 2016/08/24 22:18:35 Done.
60 arc::ArcNavigationThrottle::CloseReason::ERROR); 79 arc::ArcNavigationThrottle::CloseReason::ERROR);
61 return; 80 return;
62 } 81 }
63 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 82 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
64 if (!browser_view) { 83 if (!browser_view) {
65 throttle_cb.Run(kAppTagNoneSelected, 84 throttle_cb.Run(kAppTagNoneSelected,
66 arc::ArcNavigationThrottle::CloseReason::ERROR); 85 arc::ArcNavigationThrottle::CloseReason::ERROR);
67 return; 86 return;
68 } 87 }
69 88
70 IntentPickerBubbleView* delegate = new IntentPickerBubbleView( 89 IntentPickerBubbleView* delegate = new IntentPickerBubbleView(
71 app_info, throttle_cb, handle->GetWebContents()); 90 app_info, throttle_cb, handle->GetWebContents());
72 delegate->set_margins(gfx::Insets()); 91 delegate->set_margins(gfx::Insets());
73 delegate->set_parent_window(browser_view->GetNativeWindow()); 92 delegate->set_parent_window(browser_view->GetNativeWindow());
74 views::Widget* widget = 93 views::Widget* widget =
75 views::BubbleDialogDelegateView::CreateBubble(delegate); 94 views::BubbleDialogDelegateView::CreateBubble(delegate);
76 95
77 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 96 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
78 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 97 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
79 98
80 // Using the TopContainerBoundsInScreen Rect to specify an anchor for the the 99 // Using the TopContainerBoundsInScreen Rect to specify an anchor for the the
81 // UI. Rect allow us to set the coordinates(x,y), the width and height for the 100 // UI. Rect allow us to set the coordinates(x,y), the width and height for the
82 // new Rectangle. 101 // new Rectangle.
83 delegate->SetAnchorRect( 102 delegate->SetAnchorRect(
84 gfx::Rect(browser_view->GetTopContainerBoundsInScreen().x(), 103 gfx::Rect(browser_view->GetTopContainerBoundsInScreen().x(),
85 browser_view->GetTopContainerBoundsInScreen().y(), 104 browser_view->GetTopContainerBoundsInScreen().y(),
86 browser_view->GetTopContainerBoundsInScreen().width(), 105 browser_view->GetTopContainerBoundsInScreen().width(),
87 browser_view->GetTopContainerBoundsInScreen().height() - 106 browser_view->GetTopContainerBoundsInScreen().height() -
88 kTopContainerMerge)); 107 kTopContainerMerge));
108 widget->client_view()->AsDialogClientView()->ok_button()->SetState(
Evan Stade 2016/08/18 05:45:41 use IsDialogButtonEnabled()
djacobo_ 2016/08/24 22:18:35 Awesome, done.
109 views::Button::STATE_DISABLED);
110 widget->client_view()->AsDialogClientView()->cancel_button()->SetState(
111 views::Button::STATE_DISABLED);
89 widget->Show(); 112 widget->Show();
90 } 113 }
91 114
92 // static 115 // static
93 std::unique_ptr<IntentPickerBubbleView> 116 std::unique_ptr<IntentPickerBubbleView>
94 IntentPickerBubbleView::CreateBubbleView( 117 IntentPickerBubbleView::CreateBubbleView(
95 const std::vector<NameAndIcon>& app_info, 118 const std::vector<NameAndIcon>& app_info,
96 const ThrottleCallback& throttle_cb, 119 const ThrottleCallback& throttle_cb,
97 content::WebContents* web_contents) { 120 content::WebContents* web_contents) {
98 std::unique_ptr<IntentPickerBubbleView> bubble( 121 std::unique_ptr<IntentPickerBubbleView> bubble(
99 new IntentPickerBubbleView(app_info, throttle_cb, web_contents)); 122 new IntentPickerBubbleView(app_info, throttle_cb, web_contents));
100 bubble->Init(); 123 bubble->Init();
101 return bubble; 124 return bubble;
102 } 125 }
103 126
127 bool IntentPickerBubbleView::Accept() {
128 // Internally this button uses the |JUST ONCE| logic.
Evan Stade 2016/08/18 05:45:41 I don't understand this comment and I don't think
djacobo_ 2016/08/24 22:18:35 Done.
129 if (!was_callback_run_) {
130 was_callback_run_ = true;
Evan Stade 2016/08/18 05:45:41 instead of adding was_callback_run_, you can use R
djacobo_ 2016/08/24 22:18:35 I did use something like: if (!throttle_cb_.is_nul
djacobo_ 2016/08/24 22:41:04 Arg, I didn't undo the changes, my bad reverting t
Evan Stade 2016/08/26 22:44:23 Yes, please figure out why it's crashing. If it's
djacobo_ 2016/08/30 01:33:21 Somehow Reset()-ing the callback after actually Ru
131 throttle_cb_.Run(
132 selected_app_tag_,
133 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED);
134 }
135 return true;
136 }
137
138 bool IntentPickerBubbleView::Cancel() {
139 // Internally this button uses the |ALWAYS| logic.
140 if (!was_callback_run_) {
141 was_callback_run_ = true;
142 throttle_cb_.Run(selected_app_tag_,
143 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED);
144 }
145 return true;
146 }
147
148 bool IntentPickerBubbleView::Close() {
149 // Whenever closing the bubble without pressing |JUST ONCE| or |ALWAYS| we
150 // need to report back that the user didn't select anything.
151 if (!was_callback_run_) {
152 was_callback_run_ = true;
153 throttle_cb_.Run(
154 kAppTagNoneSelected,
155 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
156 }
157 return true;
158 }
159
160 int IntentPickerBubbleView::GetDefaultDialogButton() const {
161 return ui::DIALOG_BUTTON_NONE;
162 }
163
104 void IntentPickerBubbleView::Init() { 164 void IntentPickerBubbleView::Init() {
105 SkColor button_text_color = SkColorSetRGB(0x42, 0x85, 0xf4);
106
107 views::BoxLayout* general_layout = 165 views::BoxLayout* general_layout =
108 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 166 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
109 SetLayoutManager(general_layout); 167 SetLayoutManager(general_layout);
110 168
111 // Create a view for the upper part of the UI, managed by a GridLayout to
112 // allow precise padding.
113 View* header = new View();
114 views::GridLayout* header_layout = new views::GridLayout(header);
115 header->SetLayoutManager(header_layout);
116 views::Label* open_with = new views::Label(
117 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_OPEN_WITH));
118 open_with->SetHorizontalAlignment(gfx::ALIGN_LEFT);
119 open_with->SetFontList(gfx::FontList("Roboto-medium, 15px"));
120
121 views::ColumnSet* column_set = header_layout->AddColumnSet(0);
122 column_set->AddPaddingColumn(0, 16);
123 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
124 views::GridLayout::FIXED, kMaxWidth, kMaxWidth);
125 column_set->AddPaddingColumn(0, 16);
126 // Tell the GridLayout where to start, then proceed to place the views.
127 header_layout->AddPaddingRow(0.0, 21);
128 header_layout->StartRow(0, 0);
129 header_layout->AddView(open_with);
130 header_layout->AddPaddingRow(0.0, 24);
131
132 always_button_ = new views::LabelButton(
133 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS));
134 always_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
135 always_button_->SetFontList(gfx::FontList("Roboto-medium, 13px"));
136 always_button_->set_tag(static_cast<int>(Option::ALWAYS));
137 always_button_->SetMinSize(gfx::Size(80, 32));
138 always_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY);
139 always_button_->SetTextColor(views::Button::STATE_NORMAL, button_text_color);
140 always_button_->SetTextColor(views::Button::STATE_HOVERED, button_text_color);
141 always_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
142 always_button_->SetState(views::Button::STATE_DISABLED);
143 always_button_->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(16)));
144
145 just_once_button_ = new views::LabelButton(
146 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE));
147 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
148 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px"));
149 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE));
150 just_once_button_->SetMinSize(gfx::Size(80, 32));
151 just_once_button_->SetState(views::Button::STATE_DISABLED);
152 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY);
153 just_once_button_->SetTextColor(views::Button::STATE_NORMAL,
154 button_text_color);
155 just_once_button_->SetTextColor(views::Button::STATE_HOVERED,
156 button_text_color);
157 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
158 just_once_button_->SetBorder(
159 views::Border::CreateEmptyBorder(gfx::Insets(16)));
160
161 header_layout->StartRow(0, 0);
162 AddChildView(header);
163
164 // Creates a view to hold the views for each app. 169 // Creates a view to hold the views for each app.
165 views::View* scrollable_view = new views::View(); 170 views::View* scrollable_view = new views::View();
166 views::BoxLayout* scrollable_layout = 171 views::BoxLayout* scrollable_layout =
167 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 172 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
168 scrollable_view->SetLayoutManager(scrollable_layout); 173 scrollable_view->SetLayoutManager(scrollable_layout);
169 for (size_t i = 0; i < app_info_.size(); ++i) { 174 for (size_t i = 0; i < app_info_.size(); ++i) {
170 views::LabelButton* tmp_label = new views::LabelButton( 175 IntentPickerMenuButton* tmp_label = new IntentPickerMenuButton(
Evan Stade 2016/08/18 05:45:41 I don't think tmp_ is a good prefix for local vari
djacobo_ 2016/08/24 22:18:35 Done.
171 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); 176 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first)));
172 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS);
173 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px"));
174 tmp_label->SetImageLabelSpacing(kLabelImageSeparation);
175 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); 177 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight));
176 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight));
177 tmp_label->set_tag(i); 178 tmp_label->set_tag(i);
178 if (!app_info_[i].second.IsEmpty()) { 179 if (!app_info_[i].second.IsEmpty()) {
179 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, 180 tmp_label->SetImage(views::ImageButton::STATE_NORMAL,
180 *app_info_[i].second.ToImageSkia()); 181 *app_info_[i].second.ToImageSkia());
181 } 182 }
182 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0)); 183 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0));
183 scrollable_view->AddChildViewAt(tmp_label, i); 184 scrollable_view->AddChildViewAt(tmp_label, i);
184 } 185 }
185 186
186 scroll_view_ = new views::ScrollView(); 187 scroll_view_ = new views::ScrollView();
187 scroll_view_->SetContents(scrollable_view); 188 scroll_view_->SetContents(scrollable_view);
188 // Setting a customized ScrollBar which is shown only when the mouse pointer 189 // Setting a customized ScrollBar which is shown only when the mouse pointer
189 // is inside the ScrollView. 190 // is inside the ScrollView.
190 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); 191 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false));
191 // This part gives the scroll a fixed width and height. The height depends on 192 // This part gives the scroll a fixed width and height. The height depends on
192 // how many app candidates we got and how many we actually want to show. 193 // how many app candidates we got and how many we actually want to show.
193 // The added 0.5 on the else block allow us to let the user know there are 194 // The added 0.5 on the else block allow us to let the user know there are
194 // more than |kMaxAppResults| apps accessible by scrolling the list. 195 // more than |kMaxAppResults| apps accessible by scrolling the list.
195 if (app_info_.size() <= kMaxAppResults) { 196 if (app_info_.size() <= kMaxAppResults) {
196 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight); 197 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight);
197 } else { 198 } else {
198 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight); 199 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight);
199 } 200 }
200 AddChildView(scroll_view_); 201 AddChildView(scroll_view_);
201 202
202 // The lower part of the Picker contains only the 2 buttons 203 if (ui::MaterialDesignController::IsModeMaterial()) {
203 // |just_once_button_| and |always_button_|. 204 SetPaintToLayer(true);
204 View* footer = new View(); 205 layer()->SetMasksToBounds(true);
205 footer->SetBorder(views::Border::CreateEmptyBorder(24, 0, 12, 12)); 206 layer()->SetFillsBoundsOpaquely(false);
206 views::BoxLayout* buttons_layout = new views::BoxLayout( 207 }
207 views::BoxLayout::kHorizontal, 0, 0, kButtonSeparation); 208 }
208 footer->SetLayoutManager(buttons_layout);
209 209
210 buttons_layout->set_main_axis_alignment( 210 base::string16 IntentPickerBubbleView::GetWindowTitle() const {
211 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); 211 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_OPEN_WITH);
212 footer->AddChildView(just_once_button_); 212 }
213 footer->AddChildView(always_button_); 213
214 AddChildView(footer); 214 base::string16 IntentPickerBubbleView::GetDialogButtonLabel(
215 ui::DialogButton button) const {
216 if (button == ui::DIALOG_BUTTON_OK)
217 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE);
218 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS);
215 } 219 }
216 220
217 IntentPickerBubbleView::IntentPickerBubbleView( 221 IntentPickerBubbleView::IntentPickerBubbleView(
218 const std::vector<NameAndIcon>& app_info, 222 const std::vector<NameAndIcon>& app_info,
219 ThrottleCallback throttle_cb, 223 ThrottleCallback throttle_cb,
220 content::WebContents* web_contents) 224 content::WebContents* web_contents)
221 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, 225 : views::BubbleDialogDelegateView(nullptr /* anchor_view */,
222 views::BubbleBorder::TOP_CENTER), 226 views::BubbleBorder::TOP_CENTER),
223 WebContentsObserver(web_contents), 227 WebContentsObserver(web_contents),
224 was_callback_run_(false), 228 was_callback_run_(false),
225 throttle_cb_(throttle_cb), 229 throttle_cb_(throttle_cb),
226 selected_app_tag_(kAppTagNoneSelected), 230 selected_app_tag_(kAppTagNoneSelected),
227 always_button_(nullptr),
228 just_once_button_(nullptr),
229 scroll_view_(nullptr), 231 scroll_view_(nullptr),
230 app_info_(app_info) {} 232 app_info_(app_info) {}
231 233
232 IntentPickerBubbleView::~IntentPickerBubbleView() { 234 IntentPickerBubbleView::~IntentPickerBubbleView() {
233 SetLayoutManager(nullptr); 235 SetLayoutManager(nullptr);
234 } 236 }
235 237
236 // If the widget gets closed without an app being selected we still need to use 238 // If the widget gets closed without an app being selected we still need to use
237 // the callback so the caller can Resume the navigation. 239 // the callback so the caller can Resume the navigation.
238 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { 240 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) {
239 if (!was_callback_run_) { 241 if (!was_callback_run_) {
240 throttle_cb_.Run( 242 throttle_cb_.Run(
241 kAppTagNoneSelected, 243 kAppTagNoneSelected,
242 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); 244 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
243 was_callback_run_ = true; 245 was_callback_run_ = true;
244 } 246 }
245 } 247 }
246 248
247 int IntentPickerBubbleView::GetDialogButtons() const { 249 int IntentPickerBubbleView::GetDialogButtons() const {
248 return ui::DIALOG_BUTTON_NONE; 250 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
Evan Stade 2016/08/18 05:45:41 this is the default
djacobo_ 2016/08/24 22:18:35 Done.
249 } 251 }
250 252
251 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, 253 void IntentPickerBubbleView::ButtonPressed(views::Button* sender,
252 const ui::Event& event) { 254 const ui::Event& event) {
253 switch (sender->tag()) { 255 // The selected app must be a value in the range [0, app_info_.size()-1].
254 case static_cast<int>(Option::ALWAYS): 256 DCHECK(static_cast<size_t>(sender->tag()) < app_info_.size());
255 throttle_cb_.Run(selected_app_tag_, 257 // The user cannot click on the |always_button_| or |just_once_button_|
256 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); 258 // unless an explicit app has been selected.
257 was_callback_run_ = true; 259 if (selected_app_tag_ != kAppTagNoneSelected)
258 GetWidget()->Close(); 260 SetIntentPickerMenuButtonBackgroundColor(selected_app_tag_, SK_ColorWHITE);
259 break; 261 selected_app_tag_ = sender->tag();
260 case static_cast<int>(Option::JUST_ONCE): 262 SetIntentPickerMenuButtonBackgroundColor(selected_app_tag_,
Evan Stade 2016/08/18 05:45:41 seems like you should be setting the ink drop stat
djacobo_ 2016/08/24 22:18:35 If we wanted to use InkDropState, shouldn't we hav
bruthig 2016/08/30 19:16:36 I can't speak definitively but I agree with Evan.
djacobo_ 2016/09/06 23:21:23 As chatted offline, using a custom class that over
261 throttle_cb_.Run( 263 SkColorSetRGB(0xeb, 0xeb, 0xeb));
262 selected_app_tag_, 264 GetDialogClientView()->ok_button()->SetState(views::Button::STATE_NORMAL);
Evan Stade 2016/08/18 05:45:41 GetDialogClientView()->UpdateDialogButtons();
djacobo_ 2016/08/24 22:18:35 Done.
263 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); 265 GetDialogClientView()->cancel_button()->SetState(views::Button::STATE_NORMAL);
264 was_callback_run_ = true;
265 GetWidget()->Close();
266 break;
267 default:
268 // The selected app must be a value in the range [0, app_info_.size()-1].
269 DCHECK(static_cast<size_t>(sender->tag()) < app_info_.size());
270 // The user cannot click on the |always_button_| or |just_once_button_|
271 // unless an explicit app has been selected.
272 if (selected_app_tag_ != kAppTagNoneSelected)
273 SetLabelButtonBackgroundColor(selected_app_tag_, SK_ColorWHITE);
274 selected_app_tag_ = sender->tag();
275 SetLabelButtonBackgroundColor(selected_app_tag_,
276 SkColorSetRGB(0xeb, 0xeb, 0xeb));
277 always_button_->SetState(views::Button::STATE_NORMAL);
278 just_once_button_->SetState(views::Button::STATE_NORMAL);
279 }
280 } 266 }
281 267
282 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { 268 gfx::Size IntentPickerBubbleView::GetPreferredSize() const {
283 gfx::Size ps; 269 gfx::Size ps;
284 ps.set_width(kMaxWidth); 270 ps.set_width(kMaxWidth);
285 int apps_height = app_info_.size(); 271 int apps_height = app_info_.size();
286 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so 272 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so
287 // the user can notice that more options are available. 273 // the user can notice that more options are available.
288 if (app_info_.size() > kMaxAppResults) { 274 if (app_info_.size() > kMaxAppResults) {
289 apps_height = (kMaxAppResults + 0.5) * kRowHeight; 275 apps_height = (kMaxAppResults + 0.5) * kRowHeight;
290 } else { 276 } else {
291 apps_height *= kRowHeight; 277 apps_height *= kRowHeight;
292 } 278 }
293 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); 279 ps.set_height(apps_height);
294 return ps; 280 return ps;
295 } 281 }
296 282
297 // If the actual web_contents gets destroyed in the middle of the process we 283 // If the actual web_contents gets destroyed in the middle of the process we
298 // should inform the caller about this error. 284 // should inform the caller about this error.
299 void IntentPickerBubbleView::WebContentsDestroyed() { 285 void IntentPickerBubbleView::WebContentsDestroyed() {
300 if (!was_callback_run_) { 286 if (!was_callback_run_) {
301 throttle_cb_.Run(kAppTagNoneSelected, 287 throttle_cb_.Run(kAppTagNoneSelected,
302 arc::ArcNavigationThrottle::CloseReason::ERROR); 288 arc::ArcNavigationThrottle::CloseReason::ERROR);
303 was_callback_run_ = true; 289 was_callback_run_ = true;
304 } 290 }
305 GetWidget()->Close(); 291 GetWidget()->Close();
306 } 292 }
307 293
308 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { 294 IntentPickerMenuButton* IntentPickerBubbleView::GetIntentPickerMenuButtonAt(
295 size_t index) {
309 views::View* temp_contents = scroll_view_->contents(); 296 views::View* temp_contents = scroll_view_->contents();
310 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); 297 return static_cast<IntentPickerMenuButton*>(temp_contents->child_at(index));
311 } 298 }
312 299
313 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, 300 void IntentPickerBubbleView::SetIntentPickerMenuButtonBackgroundColor(
314 SkColor color) { 301 size_t index,
315 views::LabelButton* temp_lb = GetLabelButtonAt(index); 302 SkColor color) {
303 IntentPickerMenuButton* temp_lb = GetIntentPickerMenuButtonAt(index);
Evan Stade 2016/08/18 05:45:41 s/temp_lb/button
djacobo_ 2016/08/24 22:18:35 Done.
316 temp_lb->set_background(views::Background::CreateSolidBackground(color)); 304 temp_lb->set_background(views::Background::CreateSolidBackground(color));
317 temp_lb->SchedulePaint(); 305 temp_lb->SchedulePaint();
318 } 306 }
307
308 // Method for testing, this way we don't need to expose IntentPickerMenuButton
309 gfx::ImageSkia IntentPickerBubbleView::GetAppImageForTesting(size_t index) {
310 return GetIntentPickerMenuButtonAt(index)->GetImage(
311 views::Button::ButtonState::STATE_NORMAL);
312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698