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

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

Issue 2436543003: reland: Reusing Ok/Cancel buttons for intent picker (Closed)
Patch Set: Modifying the way I create a dummy event for the testing. 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
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
34 constexpr int kDialogDelegateInsets = 16;
32 constexpr int kRowHeight = 40; 35 constexpr int kRowHeight = 40;
33 constexpr int kMaxWidth = 320; 36 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 37
40 // UI position wrt the Top Container 38 // UI position wrt the Top Container
41 constexpr int kTopContainerMerge = 3; 39 constexpr int kTopContainerMerge = 3;
42 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 constexpr char kInvalidPackageName[] = "";
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 } // namespace
50 44
45 // IntentPickerLabelButton
46
47 // A button that represents a candidate intent handler.
48 class IntentPickerLabelButton : public views::LabelButton {
49 public:
50 IntentPickerLabelButton(views::ButtonListener* listener,
51 gfx::Image* icon,
52 const std::string& package_name,
53 const std::string& activity_name)
54 : LabelButton(listener,
55 base::UTF8ToUTF16(base::StringPiece(activity_name))),
56 package_name_(package_name) {
57 SetHorizontalAlignment(gfx::ALIGN_LEFT);
58 SetFocusBehavior(View::FocusBehavior::ALWAYS);
59 SetMinSize(gfx::Size(kMaxWidth, kRowHeight));
60 SetInkDropMode(InkDropMode::ON);
61 if (!icon->IsEmpty())
62 SetImage(views::ImageButton::STATE_NORMAL, *icon->ToImageSkia());
63 SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0));
64 }
65
66 SkColor GetInkDropBaseColor() const override { return SK_ColorBLACK; }
67
68 void MarkAsUnselected(const ui::Event* event) {
69 AnimateInkDrop(views::InkDropState::DEACTIVATED,
70 ui::LocatedEvent::FromIfValid(event));
71 }
72
73 void MarkAsSelected(const ui::Event* event) {
74 AnimateInkDrop(views::InkDropState::ACTIVATED,
75 ui::LocatedEvent::FromIfValid(event));
76 }
77
78 views::InkDropState GetTargetInkDropState() {
79 return ink_drop()->GetTargetInkDropState();
80 }
81
82 private:
83 std::string package_name_;
84
85 DISALLOW_COPY_AND_ASSIGN(IntentPickerLabelButton);
86 };
87
51 // static 88 // static
52 void IntentPickerBubbleView::ShowBubble( 89 void IntentPickerBubbleView::ShowBubble(
53 content::WebContents* web_contents, 90 content::WebContents* web_contents,
54 const std::vector<NameAndIcon>& app_info, 91 const std::vector<AppInfo>& app_info,
55 const ThrottleCallback& throttle_cb) { 92 const IntentPickerResponse& intent_picker_cb) {
56 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 93 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
57 if (!browser) { 94 if (!browser || !BrowserView::GetBrowserViewForBrowser(browser)) {
58 throttle_cb.Run(kAppTagNoneSelected, 95 intent_picker_cb.Run(kInvalidPackageName,
59 arc::ArcNavigationThrottle::CloseReason::ERROR); 96 arc::ArcNavigationThrottle::CloseReason::ERROR);
60 return; 97 return;
61 } 98 }
62 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 99 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
63 if (!browser_view) {
64 throttle_cb.Run(kAppTagNoneSelected,
65 arc::ArcNavigationThrottle::CloseReason::ERROR);
66 return;
67 }
68
69 IntentPickerBubbleView* delegate = 100 IntentPickerBubbleView* delegate =
70 new IntentPickerBubbleView(app_info, throttle_cb, web_contents); 101 new IntentPickerBubbleView(app_info, intent_picker_cb, web_contents);
71 delegate->set_margins(gfx::Insets()); 102 // TODO(djacobo): Remove the left and right insets when
103 // http://crbug.com/656662 gets fixed.
104 // Add a 1-pixel extra boundary left and right when using secondary UI.
105 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
106 delegate->set_margins(gfx::Insets(16, 1, 0, 1));
107 else
108 delegate->set_margins(gfx::Insets(16, 0, 0, 0));
72 delegate->set_parent_window(browser_view->GetNativeWindow()); 109 delegate->set_parent_window(browser_view->GetNativeWindow());
73 views::Widget* widget = 110 views::Widget* widget =
74 views::BubbleDialogDelegateView::CreateBubble(delegate); 111 views::BubbleDialogDelegateView::CreateBubble(delegate);
75 112
76 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 113 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
77 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 114 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
78 115
79 // Using the TopContainerBoundsInScreen Rect to specify an anchor for the the 116 // Using the TopContainerBoundsInScreen Rect to specify an anchor for the the
80 // UI. Rect allow us to set the coordinates(x,y), the width and height for the 117 // UI. Rect allow us to set the coordinates(x,y), the width and height for the
81 // new Rectangle. 118 // new Rectangle.
82 delegate->SetAnchorRect( 119 delegate->SetAnchorRect(
83 gfx::Rect(browser_view->GetTopContainerBoundsInScreen().x(), 120 gfx::Rect(browser_view->GetTopContainerBoundsInScreen().x(),
84 browser_view->GetTopContainerBoundsInScreen().y(), 121 browser_view->GetTopContainerBoundsInScreen().y(),
85 browser_view->GetTopContainerBoundsInScreen().width(), 122 browser_view->GetTopContainerBoundsInScreen().width(),
86 browser_view->GetTopContainerBoundsInScreen().height() - 123 browser_view->GetTopContainerBoundsInScreen().height() -
87 kTopContainerMerge)); 124 kTopContainerMerge));
125 delegate->GetDialogClientView()->set_button_row_insets(
126 gfx::Insets(kDialogDelegateInsets));
127 delegate->GetDialogClientView()->Layout();
128 delegate->GetIntentPickerLabelButtonAt(0)->MarkAsSelected(nullptr);
88 widget->Show(); 129 widget->Show();
89 } 130 }
90 131
91 // static 132 // static
92 std::unique_ptr<IntentPickerBubbleView> 133 std::unique_ptr<IntentPickerBubbleView>
93 IntentPickerBubbleView::CreateBubbleView( 134 IntentPickerBubbleView::CreateBubbleView(
94 const std::vector<NameAndIcon>& app_info, 135 const std::vector<AppInfo>& app_info,
95 const ThrottleCallback& throttle_cb, 136 const IntentPickerResponse& intent_picker_cb,
96 content::WebContents* web_contents) { 137 content::WebContents* web_contents) {
97 std::unique_ptr<IntentPickerBubbleView> bubble( 138 std::unique_ptr<IntentPickerBubbleView> bubble(
98 new IntentPickerBubbleView(app_info, throttle_cb, web_contents)); 139 new IntentPickerBubbleView(app_info, intent_picker_cb, web_contents));
99 bubble->Init(); 140 bubble->Init();
100 return bubble; 141 return bubble;
101 } 142 }
102 143
144 bool IntentPickerBubbleView::Accept() {
145 RunCallback(app_info_[selected_app_tag_].package_name,
146 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED);
147 return true;
148 }
149
150 bool IntentPickerBubbleView::Cancel() {
151 RunCallback(app_info_[selected_app_tag_].package_name,
152 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED);
153 return true;
154 }
155
156 bool IntentPickerBubbleView::Close() {
157 // Whenever closing the bubble without pressing |Just once| or |Always| we
158 // need to report back that the user didn't select anything.
159 RunCallback(kInvalidPackageName,
160 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
161 return true;
162 }
163
103 void IntentPickerBubbleView::Init() { 164 void IntentPickerBubbleView::Init() {
104 SkColor button_text_color = SkColorSetRGB(0x42, 0x85, 0xf4);
105
106 views::BoxLayout* general_layout = 165 views::BoxLayout* general_layout =
107 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 166 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
108 SetLayoutManager(general_layout); 167 SetLayoutManager(general_layout);
109 168
110 // Create a view for the upper part of the UI, managed by a GridLayout to
111 // allow precise padding.
112 View* header = new View();
113 views::GridLayout* header_layout = new views::GridLayout(header);
114 header->SetLayoutManager(header_layout);
115 views::Label* open_with = new views::Label(
116 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_OPEN_WITH));
117 open_with->SetHorizontalAlignment(gfx::ALIGN_LEFT);
118 open_with->SetFontList(gfx::FontList("Roboto-medium, 15px"));
119
120 views::ColumnSet* column_set = header_layout->AddColumnSet(0);
121 column_set->AddPaddingColumn(0, 16);
122 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
123 views::GridLayout::FIXED, kMaxWidth, kMaxWidth);
124 column_set->AddPaddingColumn(0, 16);
125 // Tell the GridLayout where to start, then proceed to place the views.
126 header_layout->AddPaddingRow(0.0, 21);
127 header_layout->StartRow(0, 0);
128 header_layout->AddView(open_with);
129 header_layout->AddPaddingRow(0.0, 24);
130
131 always_button_ = new views::LabelButton(
132 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS));
133 always_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
134 always_button_->SetFontList(gfx::FontList("Roboto-medium, 13px"));
135 always_button_->set_tag(static_cast<int>(Option::ALWAYS));
136 always_button_->SetMinSize(gfx::Size(80, 32));
137 always_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY);
138 always_button_->SetTextColor(views::Button::STATE_NORMAL, button_text_color);
139 always_button_->SetTextColor(views::Button::STATE_HOVERED, button_text_color);
140 always_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
141 always_button_->SetState(views::Button::STATE_DISABLED);
142 always_button_->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(16)));
143
144 just_once_button_ = new views::LabelButton(
145 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE));
146 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
147 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px"));
148 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE));
149 just_once_button_->SetMinSize(gfx::Size(80, 32));
150 just_once_button_->SetState(views::Button::STATE_DISABLED);
151 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY);
152 just_once_button_->SetTextColor(views::Button::STATE_NORMAL,
153 button_text_color);
154 just_once_button_->SetTextColor(views::Button::STATE_HOVERED,
155 button_text_color);
156 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
157 just_once_button_->SetBorder(
158 views::Border::CreateEmptyBorder(gfx::Insets(16)));
159
160 header_layout->StartRow(0, 0);
161 AddChildView(header);
162
163 // Creates a view to hold the views for each app. 169 // Creates a view to hold the views for each app.
164 views::View* scrollable_view = new views::View(); 170 views::View* scrollable_view = new views::View();
165 views::BoxLayout* scrollable_layout = 171 views::BoxLayout* scrollable_layout =
166 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 172 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
167 scrollable_view->SetLayoutManager(scrollable_layout); 173 scrollable_view->SetLayoutManager(scrollable_layout);
168 for (size_t i = 0; i < app_info_.size(); ++i) { 174 for (size_t i = 0; i < app_info_.size(); ++i) {
169 views::LabelButton* tmp_label = new views::LabelButton( 175 IntentPickerLabelButton* app_button = new IntentPickerLabelButton(
170 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); 176 this, &app_info_[i].icon, app_info_[i].package_name,
171 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); 177 app_info_[i].activity_name);
172 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); 178 app_button->set_tag(i);
173 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); 179 scrollable_view->AddChildViewAt(app_button, i);
174 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight));
175 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight));
176 tmp_label->set_tag(i);
177 if (!app_info_[i].second.IsEmpty()) {
178 tmp_label->SetImage(views::ImageButton::STATE_NORMAL,
179 *app_info_[i].second.ToImageSkia());
180 }
181 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0));
182 scrollable_view->AddChildViewAt(tmp_label, i);
183 } 180 }
184 181
185 scroll_view_ = new views::ScrollView(); 182 scroll_view_ = new views::ScrollView();
183 scroll_view_->EnableViewPortLayer();
186 scroll_view_->SetContents(scrollable_view); 184 scroll_view_->SetContents(scrollable_view);
187 // Setting a customized ScrollBar which is shown only when the mouse pointer 185 // Setting a customized ScrollBar which is shown only when the mouse pointer
188 // is inside the ScrollView. 186 // is inside the ScrollView.
189 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); 187 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false));
190 // This part gives the scroll a fixed width and height. The height depends on 188 // This part gives the scroll a fixed width and height. The height depends on
191 // how many app candidates we got and how many we actually want to show. 189 // how many app candidates we got and how many we actually want to show.
192 // The added 0.5 on the else block allow us to let the user know there are 190 // The added 0.5 on the else block allow us to let the user know there are
193 // more than |kMaxAppResults| apps accessible by scrolling the list. 191 // more than |kMaxAppResults| apps accessible by scrolling the list.
194 if (app_info_.size() <= kMaxAppResults) { 192 if (app_info_.size() <= kMaxAppResults) {
195 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight); 193 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight);
196 } else { 194 } else {
197 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight); 195 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight);
198 } 196 }
199 AddChildView(scroll_view_); 197 AddChildView(scroll_view_);
198 }
200 199
201 // The lower part of the Picker contains only the 2 buttons 200 base::string16 IntentPickerBubbleView::GetWindowTitle() const {
202 // |just_once_button_| and |always_button_|. 201 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_OPEN_WITH);
203 View* footer = new View(); 202 }
204 footer->SetBorder(views::Border::CreateEmptyBorder(24, 0, 12, 12));
205 views::BoxLayout* buttons_layout = new views::BoxLayout(
206 views::BoxLayout::kHorizontal, 0, 0, kButtonSeparation);
207 footer->SetLayoutManager(buttons_layout);
208 203
209 buttons_layout->set_main_axis_alignment( 204 base::string16 IntentPickerBubbleView::GetDialogButtonLabel(
210 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); 205 ui::DialogButton button) const {
211 footer->AddChildView(just_once_button_); 206 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK
212 footer->AddChildView(always_button_); 207 ? IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE
213 AddChildView(footer); 208 : IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS);
214 } 209 }
215 210
216 IntentPickerBubbleView::IntentPickerBubbleView( 211 IntentPickerBubbleView::IntentPickerBubbleView(
217 const std::vector<NameAndIcon>& app_info, 212 const std::vector<AppInfo>& app_info,
218 ThrottleCallback throttle_cb, 213 IntentPickerResponse intent_picker_cb,
219 content::WebContents* web_contents) 214 content::WebContents* web_contents)
220 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, 215 : views::BubbleDialogDelegateView(nullptr /* anchor_view */,
221 views::BubbleBorder::TOP_CENTER), 216 views::BubbleBorder::TOP_CENTER),
222 WebContentsObserver(web_contents), 217 WebContentsObserver(web_contents),
223 was_callback_run_(false), 218 intent_picker_cb_(intent_picker_cb),
224 throttle_cb_(throttle_cb), 219 selected_app_tag_(0),
225 selected_app_tag_(kAppTagNoneSelected),
226 always_button_(nullptr),
227 just_once_button_(nullptr),
228 scroll_view_(nullptr), 220 scroll_view_(nullptr),
229 app_info_(app_info) {} 221 app_info_(app_info) {}
230 222
231 IntentPickerBubbleView::~IntentPickerBubbleView() { 223 IntentPickerBubbleView::~IntentPickerBubbleView() {
232 SetLayoutManager(nullptr); 224 SetLayoutManager(nullptr);
233 } 225 }
234 226
235 // If the widget gets closed without an app being selected we still need to use 227 // If the widget gets closed without an app being selected we still need to use
236 // the callback so the caller can Resume the navigation. 228 // the callback so the caller can Resume the navigation.
237 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { 229 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) {
238 if (!was_callback_run_) { 230 RunCallback(kInvalidPackageName,
239 was_callback_run_ = true; 231 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
240 throttle_cb_.Run(
241 kAppTagNoneSelected,
242 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
243 }
244 }
245
246 int IntentPickerBubbleView::GetDialogButtons() const {
247 return ui::DIALOG_BUTTON_NONE;
248 } 232 }
249 233
250 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, 234 void IntentPickerBubbleView::ButtonPressed(views::Button* sender,
251 const ui::Event& event) { 235 const ui::Event& event) {
252 switch (sender->tag()) { 236 // The selected app must be a value in the range [0, app_info_.size()-1].
253 case static_cast<int>(Option::ALWAYS): 237 DCHECK_LT(static_cast<size_t>(sender->tag()), app_info_.size());
254 was_callback_run_ = true; 238 GetIntentPickerLabelButtonAt(selected_app_tag_)->MarkAsUnselected(&event);
255 throttle_cb_.Run(selected_app_tag_, 239
256 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); 240 selected_app_tag_ = sender->tag();
257 GetWidget()->Close(); 241 GetIntentPickerLabelButtonAt(selected_app_tag_)->MarkAsSelected(&event);
258 break;
259 case static_cast<int>(Option::JUST_ONCE):
260 was_callback_run_ = true;
261 throttle_cb_.Run(
262 selected_app_tag_,
263 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED);
264 GetWidget()->Close();
265 break;
266 default:
267 // The selected app must be a value in the range [0, app_info_.size()-1].
268 DCHECK(static_cast<size_t>(sender->tag()) < app_info_.size());
269 // The user cannot click on the |always_button_| or |just_once_button_|
270 // unless an explicit app has been selected.
271 if (selected_app_tag_ != kAppTagNoneSelected)
272 SetLabelButtonBackgroundColor(selected_app_tag_, SK_ColorWHITE);
273 selected_app_tag_ = sender->tag();
274 SetLabelButtonBackgroundColor(selected_app_tag_,
275 SkColorSetRGB(0xeb, 0xeb, 0xeb));
276 always_button_->SetState(views::Button::STATE_NORMAL);
277 just_once_button_->SetState(views::Button::STATE_NORMAL);
278 }
279 } 242 }
280 243
281 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { 244 gfx::Size IntentPickerBubbleView::GetPreferredSize() const {
282 gfx::Size ps; 245 gfx::Size ps;
283 ps.set_width(kMaxWidth); 246 ps.set_width(kMaxWidth);
284 int apps_height = app_info_.size(); 247 int apps_height = app_info_.size();
285 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so 248 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so
286 // the user can notice that more options are available. 249 // the user can notice that more options are available.
287 if (app_info_.size() > kMaxAppResults) { 250 if (app_info_.size() > kMaxAppResults) {
288 apps_height = (kMaxAppResults + 0.5) * kRowHeight; 251 apps_height = (kMaxAppResults + 0.5) * kRowHeight;
289 } else { 252 } else {
290 apps_height *= kRowHeight; 253 apps_height *= kRowHeight;
291 } 254 }
292 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); 255 ps.set_height(apps_height + kDialogDelegateInsets);
293 return ps; 256 return ps;
294 } 257 }
295 258
296 // If the actual web_contents gets destroyed in the middle of the process we 259 // If the actual web_contents gets destroyed in the middle of the process we
297 // should inform the caller about this error. 260 // should inform the caller about this error.
298 void IntentPickerBubbleView::WebContentsDestroyed() { 261 void IntentPickerBubbleView::WebContentsDestroyed() {
299 if (!was_callback_run_) {
300 was_callback_run_ = true;
301 throttle_cb_.Run(kAppTagNoneSelected,
302 arc::ArcNavigationThrottle::CloseReason::ERROR);
303 }
304 GetWidget()->Close(); 262 GetWidget()->Close();
305 } 263 }
306 264
307 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { 265 IntentPickerLabelButton* IntentPickerBubbleView::GetIntentPickerLabelButtonAt(
266 size_t index) {
308 views::View* temp_contents = scroll_view_->contents(); 267 views::View* temp_contents = scroll_view_->contents();
309 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); 268 return static_cast<IntentPickerLabelButton*>(temp_contents->child_at(index));
310 } 269 }
311 270
312 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, 271 void IntentPickerBubbleView::RunCallback(
313 SkColor color) { 272 std::string package,
314 views::LabelButton* temp_lb = GetLabelButtonAt(index); 273 arc::ArcNavigationThrottle::CloseReason close_reason) {
315 temp_lb->set_background(views::Background::CreateSolidBackground(color)); 274 if (!intent_picker_cb_.is_null()) {
316 temp_lb->SchedulePaint(); 275 // We must ensure |intent_picker_cb_| is only Run() once, this is why we
276 // have a temporary |callback| helper, so we can set the original callback
277 // to null and still report back to whoever started the UI.
278 auto callback = intent_picker_cb_;
279 intent_picker_cb_.Reset();
280 callback.Run(package, close_reason);
281 }
317 } 282 }
283
284 gfx::ImageSkia IntentPickerBubbleView::GetAppImageForTesting(size_t index) {
285 return GetIntentPickerLabelButtonAt(index)->GetImage(
286 views::Button::ButtonState::STATE_NORMAL);
287 }
288
289 views::InkDropState IntentPickerBubbleView::GetInkDropStateForTesting(
290 size_t index) {
291 return GetIntentPickerLabelButtonAt(index)->GetTargetInkDropState();
292 }
293
294 void IntentPickerBubbleView::PressButtonForTesting(size_t index,
295 const ui::Event& event) {
296 views::Button* button =
297 static_cast<views::Button*>(GetIntentPickerLabelButtonAt(index));
298 ButtonPressed(button, event);
299 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/intent_picker_bubble_view.h ('k') | chrome/browser/ui/views/intent_picker_bubble_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698