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

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: Changing strings to lowercase. Created 4 years, 3 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_host_view.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
37 constexpr int kButtonSeparation = 8;
38 constexpr int kLabelImageSeparation = 12;
39 36
40 // UI position wrt the Top Container 37 // UI position wrt the Top Container
41 constexpr int kTopContainerMerge = 3; 38 constexpr int kTopContainerMerge = 3;
42 constexpr size_t kAppTagNoneSelected = static_cast<size_t>(-1); 39 constexpr size_t kAppTagNoneSelected = static_cast<size_t>(-1);
43 40
44 // Arbitrary negative values to use as tags on the |always_button_| and 41 } // 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 42
49 } // namespace 43 // IntentPickerMenuButton
Evan Stade 2016/09/14 17:48:00 this is not a MenuButton (i.e. doesn't inherit fro
djacobo_ 2016/09/14 21:29:35 You are right this is kind of deceiving, done.
44
45 // This is a convenience class for the buttons on the intent picker so we can
46 // manipulate the internal hovering behavior.
47 class IntentPickerMenuButton : public views::LabelButton {
48 public:
49 IntentPickerMenuButton(views::ButtonListener* listener,
50 const base::string16& title)
51 : LabelButton(listener, title) {
52 SetHorizontalAlignment(gfx::ALIGN_LEFT);
53 SetFocusBehavior(View::FocusBehavior::ALWAYS);
54 SetInkDropMode(InkDropMode::ON);
55 }
56
57 SkColor GetInkDropBaseColor() const override { return SK_ColorBLACK; }
58
59 void MarkAsUnselected(const ui::Event& event) {
60 AnimateInkDrop(views::InkDropState::DEACTIVATED,
Evan Stade 2016/09/14 17:47:59 I thought you wanted the highlight effect, not an
djacobo_ 2016/09/14 21:29:34 We decided to go with ink drops, as it is at the m
Evan Stade 2016/09/14 21:53:08 did you decide to go with ink drops because that's
djacobo_ 2016/09/16 01:23:08 Pretty much because it is what it works ATM, but a
61 ui::LocatedEvent::FromIfValid(&event));
62 }
63
64 void MarkAsSelected(const ui::Event& event) {
65 AnimateInkDrop(views::InkDropState::ACTIVATED,
66 ui::LocatedEvent::FromIfValid(&event));
67 }
68
69 views::InkDropState GetTargetInkDropState() {
70 return ink_drop()->GetTargetInkDropState();
71 }
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(IntentPickerMenuButton);
75 };
50 76
51 // static 77 // static
52 void IntentPickerBubbleView::ShowBubble( 78 void IntentPickerBubbleView::ShowBubble(
53 content::NavigationHandle* handle, 79 content::NavigationHandle* handle,
54 const std::vector<NameAndIcon>& app_info, 80 const std::vector<NameAndIcon>& app_info,
55 const ThrottleCallback& throttle_cb) { 81 const ThrottleCallback& throttle_cb) {
56 Browser* browser = 82 Browser* browser =
57 chrome::FindBrowserWithWebContents(handle->GetWebContents()); 83 chrome::FindBrowserWithWebContents(handle->GetWebContents());
58 if (!browser) { 84 if (!browser || !BrowserView::GetBrowserViewForBrowser(browser)) {
59 throttle_cb.Run(kAppTagNoneSelected, 85 throttle_cb.Run(kAppTagNoneSelected,
60 arc::ArcNavigationThrottle::CloseReason::ERROR); 86 arc::ArcNavigationThrottle::CloseReason::ERROR);
61 return; 87 return;
62 } 88 }
63 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 89 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
64 if (!browser_view) {
65 throttle_cb.Run(kAppTagNoneSelected,
66 arc::ArcNavigationThrottle::CloseReason::ERROR);
67 return;
68 }
69
70 IntentPickerBubbleView* delegate = new IntentPickerBubbleView( 90 IntentPickerBubbleView* delegate = new IntentPickerBubbleView(
71 app_info, throttle_cb, handle->GetWebContents()); 91 app_info, throttle_cb, handle->GetWebContents());
72 delegate->set_margins(gfx::Insets()); 92 delegate->set_margins(gfx::Insets());
73 delegate->set_parent_window(browser_view->GetNativeWindow()); 93 delegate->set_parent_window(browser_view->GetNativeWindow());
74 views::Widget* widget = 94 views::Widget* widget =
75 views::BubbleDialogDelegateView::CreateBubble(delegate); 95 views::BubbleDialogDelegateView::CreateBubble(delegate);
76 96
77 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 97 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
78 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 98 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
79 99
(...skipping 14 matching lines...) Expand all
94 IntentPickerBubbleView::CreateBubbleView( 114 IntentPickerBubbleView::CreateBubbleView(
95 const std::vector<NameAndIcon>& app_info, 115 const std::vector<NameAndIcon>& app_info,
96 const ThrottleCallback& throttle_cb, 116 const ThrottleCallback& throttle_cb,
97 content::WebContents* web_contents) { 117 content::WebContents* web_contents) {
98 std::unique_ptr<IntentPickerBubbleView> bubble( 118 std::unique_ptr<IntentPickerBubbleView> bubble(
99 new IntentPickerBubbleView(app_info, throttle_cb, web_contents)); 119 new IntentPickerBubbleView(app_info, throttle_cb, web_contents));
100 bubble->Init(); 120 bubble->Init();
101 return bubble; 121 return bubble;
102 } 122 }
103 123
124 bool IntentPickerBubbleView::Accept() {
125 if (!throttle_cb_.is_null()) {
126 auto callback = throttle_cb_;
127 throttle_cb_.Reset();
128 callback.Run(selected_app_tag_,
129 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED);
130 }
131 return true;
132 }
133
134 bool IntentPickerBubbleView::Cancel() {
135 if (!throttle_cb_.is_null()) {
136 auto callback = throttle_cb_;
137 throttle_cb_.Reset();
138 callback.Run(selected_app_tag_,
139 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED);
140 }
141 return true;
142 }
143
144 bool IntentPickerBubbleView::Close() {
145 // Whenever closing the bubble without pressing |JUST ONCE| or |ALWAYS| we
146 // need to report back that the user didn't select anything.
147 if (!throttle_cb_.is_null()) {
148 auto callback = throttle_cb_;
149 throttle_cb_.Reset();
150 callback.Run(kAppTagNoneSelected,
151 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
152 }
153 return true;
154 }
155
156 int IntentPickerBubbleView::GetDefaultDialogButton() const {
157 return ui::DIALOG_BUTTON_NONE;
Evan Stade 2016/09/14 17:48:00 this means that the dialog won't respond to "enter
djacobo_ 2016/09/14 21:29:35 You may be right, we should select "Just once" by
158 }
159
160 bool IntentPickerBubbleView::IsDialogButtonEnabled(
161 ui::DialogButton button) const {
162 // Both buttons are enabled only when the user selected one of the apps.
163 return selected_app_tag_ != kAppTagNoneSelected;
164 }
165
104 void IntentPickerBubbleView::Init() { 166 void IntentPickerBubbleView::Init() {
105 SkColor button_text_color = SkColorSetRGB(0x42, 0x85, 0xf4);
106
107 views::BoxLayout* general_layout = 167 views::BoxLayout* general_layout =
108 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 168 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
109 SetLayoutManager(general_layout); 169 SetLayoutManager(general_layout);
110 170
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. 171 // Creates a view to hold the views for each app.
165 views::View* scrollable_view = new views::View(); 172 views::View* scrollable_view = new views::View();
166 views::BoxLayout* scrollable_layout = 173 views::BoxLayout* scrollable_layout =
167 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 174 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
168 scrollable_view->SetLayoutManager(scrollable_layout); 175 scrollable_view->SetLayoutManager(scrollable_layout);
169 for (size_t i = 0; i < app_info_.size(); ++i) { 176 for (size_t i = 0; i < app_info_.size(); ++i) {
170 views::LabelButton* tmp_label = new views::LabelButton( 177 IntentPickerMenuButton* app_button = new IntentPickerMenuButton(
171 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); 178 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first)));
172 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); 179 app_button->SetMinSize(gfx::Size(kMaxWidth, kRowHeight));
173 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); 180 app_button->set_tag(i);
174 tmp_label->SetImageLabelSpacing(kLabelImageSeparation);
175 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight));
176 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight));
177 tmp_label->set_tag(i);
178 if (!app_info_[i].second.IsEmpty()) { 181 if (!app_info_[i].second.IsEmpty()) {
179 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, 182 app_button->SetImage(views::ImageButton::STATE_NORMAL,
180 *app_info_[i].second.ToImageSkia()); 183 *app_info_[i].second.ToImageSkia());
181 } 184 }
182 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0)); 185 app_button->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0));
183 scrollable_view->AddChildViewAt(tmp_label, i); 186 scrollable_view->AddChildViewAt(app_button, i);
184 } 187 }
185 188
186 scroll_view_ = new views::ScrollView(); 189 scroll_view_ = new views::ScrollView();
187 scroll_view_->SetContents(scrollable_view); 190 scroll_view_->SetContents(scrollable_view);
188 // Setting a customized ScrollBar which is shown only when the mouse pointer 191 // Setting a customized ScrollBar which is shown only when the mouse pointer
189 // is inside the ScrollView. 192 // is inside the ScrollView.
190 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); 193 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false));
191 // This part gives the scroll a fixed width and height. The height depends on 194 // 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. 195 // 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 196 // 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. 197 // more than |kMaxAppResults| apps accessible by scrolling the list.
195 if (app_info_.size() <= kMaxAppResults) { 198 if (app_info_.size() <= kMaxAppResults) {
196 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight); 199 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight);
197 } else { 200 } else {
198 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight); 201 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight);
199 } 202 }
200 AddChildView(scroll_view_); 203 AddChildView(scroll_view_);
201 204
202 // The lower part of the Picker contains only the 2 buttons 205 // TODO(djacobo|bruthig): Investigate why the ScrollView does not clip child
203 // |just_once_button_| and |always_button_|. 206 // view layers when the Ink Drop is active.
204 View* footer = new View(); 207 SetPaintToLayer(true);
205 footer->SetBorder(views::Border::CreateEmptyBorder(24, 0, 12, 12)); 208 layer()->SetMasksToBounds(true);
206 views::BoxLayout* buttons_layout = new views::BoxLayout( 209 layer()->SetFillsBoundsOpaquely(false);
207 views::BoxLayout::kHorizontal, 0, 0, kButtonSeparation); 210 }
208 footer->SetLayoutManager(buttons_layout);
209 211
210 buttons_layout->set_main_axis_alignment( 212 base::string16 IntentPickerBubbleView::GetWindowTitle() const {
211 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); 213 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_OPEN_WITH);
212 footer->AddChildView(just_once_button_); 214 }
213 footer->AddChildView(always_button_); 215
214 AddChildView(footer); 216 base::string16 IntentPickerBubbleView::GetDialogButtonLabel(
217 ui::DialogButton button) const {
218 if (button == ui::DIALOG_BUTTON_OK)
219 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE);
220 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS);
215 } 221 }
216 222
217 IntentPickerBubbleView::IntentPickerBubbleView( 223 IntentPickerBubbleView::IntentPickerBubbleView(
218 const std::vector<NameAndIcon>& app_info, 224 const std::vector<NameAndIcon>& app_info,
219 ThrottleCallback throttle_cb, 225 ThrottleCallback throttle_cb,
220 content::WebContents* web_contents) 226 content::WebContents* web_contents)
221 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, 227 : views::BubbleDialogDelegateView(nullptr /* anchor_view */,
222 views::BubbleBorder::TOP_CENTER), 228 views::BubbleBorder::TOP_CENTER),
223 WebContentsObserver(web_contents), 229 WebContentsObserver(web_contents),
224 was_callback_run_(false),
225 throttle_cb_(throttle_cb), 230 throttle_cb_(throttle_cb),
226 selected_app_tag_(kAppTagNoneSelected), 231 selected_app_tag_(kAppTagNoneSelected),
227 always_button_(nullptr),
228 just_once_button_(nullptr),
229 scroll_view_(nullptr), 232 scroll_view_(nullptr),
230 app_info_(app_info) {} 233 app_info_(app_info) {}
231 234
232 IntentPickerBubbleView::~IntentPickerBubbleView() { 235 IntentPickerBubbleView::~IntentPickerBubbleView() {
233 SetLayoutManager(nullptr); 236 SetLayoutManager(nullptr);
234 } 237 }
235 238
236 // If the widget gets closed without an app being selected we still need to use 239 // 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. 240 // the callback so the caller can Resume the navigation.
238 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { 241 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) {
239 if (!was_callback_run_) { 242 if (!throttle_cb_.is_null()) {
240 throttle_cb_.Run( 243 auto callback = throttle_cb_;
241 kAppTagNoneSelected, 244 throttle_cb_.Reset();
242 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); 245 callback.Run(kAppTagNoneSelected,
243 was_callback_run_ = true; 246 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
244 } 247 }
245 } 248 }
246 249
247 int IntentPickerBubbleView::GetDialogButtons() const {
248 return ui::DIALOG_BUTTON_NONE;
249 }
250
251 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, 250 void IntentPickerBubbleView::ButtonPressed(views::Button* sender,
252 const ui::Event& event) { 251 const ui::Event& event) {
253 switch (sender->tag()) { 252 // The selected app must be a value in the range [0, app_info_.size()-1].
254 case static_cast<int>(Option::ALWAYS): 253 DCHECK(static_cast<size_t>(sender->tag()) < app_info_.size());
Evan Stade 2016/09/14 17:47:59 DCHECK_LT?
djacobo_ 2016/09/14 21:29:34 Done.
255 throttle_cb_.Run(selected_app_tag_, 254 if (selected_app_tag_ != kAppTagNoneSelected)
256 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); 255 GetIntentPickerMenuButtonAt(selected_app_tag_)->MarkAsUnselected(event);
257 was_callback_run_ = true; 256
258 GetWidget()->Close(); 257 selected_app_tag_ = sender->tag();
259 break; 258 GetIntentPickerMenuButtonAt(selected_app_tag_)->MarkAsSelected(event);
260 case static_cast<int>(Option::JUST_ONCE): 259
261 throttle_cb_.Run( 260 // This may not have the integrated |Accept| and |Cancel| buttons because of
262 selected_app_tag_, 261 // how the class gets created for testing.
263 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); 262 if (GetWidget())
264 was_callback_run_ = true; 263 GetDialogClientView()->UpdateDialogButtons();
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 } 264 }
281 265
282 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { 266 gfx::Size IntentPickerBubbleView::GetPreferredSize() const {
283 gfx::Size ps; 267 gfx::Size ps;
284 ps.set_width(kMaxWidth); 268 ps.set_width(kMaxWidth);
285 int apps_height = app_info_.size(); 269 int apps_height = app_info_.size();
286 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so 270 // 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. 271 // the user can notice that more options are available.
288 if (app_info_.size() > kMaxAppResults) { 272 if (app_info_.size() > kMaxAppResults) {
289 apps_height = (kMaxAppResults + 0.5) * kRowHeight; 273 apps_height = (kMaxAppResults + 0.5) * kRowHeight;
290 } else { 274 } else {
291 apps_height *= kRowHeight; 275 apps_height *= kRowHeight;
292 } 276 }
293 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); 277 ps.set_height(apps_height);
294 return ps; 278 return ps;
295 } 279 }
296 280
297 // If the actual web_contents gets destroyed in the middle of the process we 281 // If the actual web_contents gets destroyed in the middle of the process we
298 // should inform the caller about this error. 282 // should inform the caller about this error.
299 void IntentPickerBubbleView::WebContentsDestroyed() { 283 void IntentPickerBubbleView::WebContentsDestroyed() {
300 if (!was_callback_run_) { 284 if (!throttle_cb_.is_null()) {
301 throttle_cb_.Run(kAppTagNoneSelected, 285 auto callback = throttle_cb_;
302 arc::ArcNavigationThrottle::CloseReason::ERROR); 286 throttle_cb_.Reset();
303 was_callback_run_ = true; 287 callback.Run(kAppTagNoneSelected,
288 arc::ArcNavigationThrottle::CloseReason::ERROR);
304 } 289 }
305 GetWidget()->Close(); 290 GetWidget()->Close();
306 } 291 }
307 292
308 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { 293 IntentPickerMenuButton* IntentPickerBubbleView::GetIntentPickerMenuButtonAt(
294 size_t index) {
309 views::View* temp_contents = scroll_view_->contents(); 295 views::View* temp_contents = scroll_view_->contents();
310 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); 296 return static_cast<IntentPickerMenuButton*>(temp_contents->child_at(index));
311 } 297 }
312 298
313 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, 299 gfx::ImageSkia IntentPickerBubbleView::GetAppImageForTesting(size_t index) {
314 SkColor color) { 300 return GetIntentPickerMenuButtonAt(index)->GetImage(
315 views::LabelButton* temp_lb = GetLabelButtonAt(index); 301 views::Button::ButtonState::STATE_NORMAL);
316 temp_lb->set_background(views::Background::CreateSolidBackground(color));
317 temp_lb->SchedulePaint();
318 } 302 }
303
304 views::InkDropState IntentPickerBubbleView::GetInkDropStateForTesting(
305 size_t index) {
306 return GetIntentPickerMenuButtonAt(index)->GetTargetInkDropState();
307 }
308
309 void IntentPickerBubbleView::PressButtonForTesting(size_t index,
310 const ui::Event& event) {
311 views::Button* button =
312 static_cast<views::Button*>(GetIntentPickerMenuButtonAt(index));
313 ButtonPressed(button, event);
314 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698