Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
|
bruthig
2016/08/30 19:16:37
Is this needed?
djacobo_
2016/09/06 23:21:24
I guess I tried to use .../ink_drop_host_view.h re
| |
| 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" |
| 23 #include "ui/views/controls/button/md_text_button.h" | |
| 21 #include "ui/views/controls/scroll_view.h" | 24 #include "ui/views/controls/scroll_view.h" |
| 22 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 25 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
| 23 #include "ui/views/layout/box_layout.h" | 26 #include "ui/views/layout/box_layout.h" |
| 24 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
| 25 #include "ui/views/window/dialog_client_view.h" | 28 #include "ui/views/window/dialog_client_view.h" |
| 26 | 29 |
| 27 namespace { | 30 namespace { |
| 28 | 31 |
| 29 // Using |kMaxAppResults| as a measure of how many apps we want to show. | 32 // Using |kMaxAppResults| as a measure of how many apps we want to show. |
| 30 constexpr size_t kMaxAppResults = arc::ArcNavigationThrottle::kMaxAppResults; | 33 constexpr size_t kMaxAppResults = arc::ArcNavigationThrottle::kMaxAppResults; |
| 31 // Main components sizes | 34 // Main components sizes |
| 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); | 40 constexpr size_t kAppTagNoneSelected = static_cast<size_t>(-1); |
| 43 | 41 |
| 44 // Arbitrary negative values to use as tags on the |always_button_| and | |
| 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 | |
| 49 } // namespace | 42 } // namespace |
| 50 | 43 |
| 51 // static | 44 // static |
| 52 void IntentPickerBubbleView::ShowBubble( | 45 void IntentPickerBubbleView::ShowBubble( |
| 53 content::NavigationHandle* handle, | 46 content::NavigationHandle* handle, |
| 54 const std::vector<NameAndIcon>& app_info, | 47 const std::vector<NameAndIcon>& app_info, |
| 55 const ThrottleCallback& throttle_cb) { | 48 const ThrottleCallback& throttle_cb) { |
| 56 Browser* browser = | 49 Browser* browser = |
| 57 chrome::FindBrowserWithWebContents(handle->GetWebContents()); | 50 chrome::FindBrowserWithWebContents(handle->GetWebContents()); |
| 58 if (!browser) { | 51 if (!browser || !BrowserView::GetBrowserViewForBrowser(browser)) { |
| 59 throttle_cb.Run(kAppTagNoneSelected, | 52 throttle_cb.Run(kAppTagNoneSelected, |
| 60 arc::ArcNavigationThrottle::CloseReason::ERROR); | 53 arc::ArcNavigationThrottle::CloseReason::ERROR); |
| 61 return; | 54 return; |
| 62 } | 55 } |
| 63 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 56 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( | 57 IntentPickerBubbleView* delegate = new IntentPickerBubbleView( |
| 71 app_info, throttle_cb, handle->GetWebContents()); | 58 app_info, throttle_cb, handle->GetWebContents()); |
| 72 delegate->set_margins(gfx::Insets()); | 59 delegate->set_margins(gfx::Insets()); |
| 73 delegate->set_parent_window(browser_view->GetNativeWindow()); | 60 delegate->set_parent_window(browser_view->GetNativeWindow()); |
| 74 views::Widget* widget = | 61 views::Widget* widget = |
| 75 views::BubbleDialogDelegateView::CreateBubble(delegate); | 62 views::BubbleDialogDelegateView::CreateBubble(delegate); |
| 76 | 63 |
| 77 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 64 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 78 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 65 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 79 | 66 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 94 IntentPickerBubbleView::CreateBubbleView( | 81 IntentPickerBubbleView::CreateBubbleView( |
| 95 const std::vector<NameAndIcon>& app_info, | 82 const std::vector<NameAndIcon>& app_info, |
| 96 const ThrottleCallback& throttle_cb, | 83 const ThrottleCallback& throttle_cb, |
| 97 content::WebContents* web_contents) { | 84 content::WebContents* web_contents) { |
| 98 std::unique_ptr<IntentPickerBubbleView> bubble( | 85 std::unique_ptr<IntentPickerBubbleView> bubble( |
| 99 new IntentPickerBubbleView(app_info, throttle_cb, web_contents)); | 86 new IntentPickerBubbleView(app_info, throttle_cb, web_contents)); |
| 100 bubble->Init(); | 87 bubble->Init(); |
| 101 return bubble; | 88 return bubble; |
| 102 } | 89 } |
| 103 | 90 |
| 91 bool IntentPickerBubbleView::Accept() { | |
| 92 if (!throttle_cb_.is_null()) { | |
| 93 auto callback = throttle_cb_; | |
| 94 throttle_cb_.Reset(); | |
| 95 callback.Run(selected_app_tag_, | |
| 96 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); | |
| 97 } | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 bool IntentPickerBubbleView::Cancel() { | |
| 102 if (!throttle_cb_.is_null()) { | |
| 103 auto callback = throttle_cb_; | |
| 104 throttle_cb_.Reset(); | |
| 105 callback.Run(selected_app_tag_, | |
| 106 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | |
| 107 } | |
| 108 return true; | |
| 109 } | |
| 110 | |
| 111 bool IntentPickerBubbleView::Close() { | |
| 112 // Whenever closing the bubble without pressing |JUST ONCE| or |ALWAYS| we | |
| 113 // need to report back that the user didn't select anything. | |
| 114 if (!throttle_cb_.is_null()) { | |
| 115 auto callback = throttle_cb_; | |
| 116 throttle_cb_.Reset(); | |
| 117 callback.Run(kAppTagNoneSelected, | |
| 118 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); | |
| 119 } | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 int IntentPickerBubbleView::GetDefaultDialogButton() const { | |
| 124 return ui::DIALOG_BUTTON_NONE; | |
| 125 } | |
| 126 | |
| 127 bool IntentPickerBubbleView::IsDialogButtonEnabled( | |
| 128 ui::DialogButton button) const { | |
| 129 // Both buttons are enabled only when the user selected one of the apps. | |
| 130 return selected_app_tag_ != kAppTagNoneSelected; | |
| 131 } | |
| 132 | |
| 104 void IntentPickerBubbleView::Init() { | 133 void IntentPickerBubbleView::Init() { |
| 105 SkColor button_text_color = SkColorSetRGB(0x42, 0x85, 0xf4); | |
| 106 | |
| 107 views::BoxLayout* general_layout = | 134 views::BoxLayout* general_layout = |
| 108 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 135 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
| 109 SetLayoutManager(general_layout); | 136 SetLayoutManager(general_layout); |
| 110 | 137 |
| 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. | 138 // Creates a view to hold the views for each app. |
| 165 views::View* scrollable_view = new views::View(); | 139 views::View* scrollable_view = new views::View(); |
| 166 views::BoxLayout* scrollable_layout = | 140 views::BoxLayout* scrollable_layout = |
| 167 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 141 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
| 168 scrollable_view->SetLayoutManager(scrollable_layout); | 142 scrollable_view->SetLayoutManager(scrollable_layout); |
| 169 for (size_t i = 0; i < app_info_.size(); ++i) { | 143 for (size_t i = 0; i < app_info_.size(); ++i) { |
| 170 views::LabelButton* tmp_label = new views::LabelButton( | 144 views::LabelButton* app_button = |
| 171 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); | 145 views::MdTextButton::CreateSecondaryUiButton( |
| 172 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 146 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); |
| 173 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); | 147 app_button->set_ink_drop_base_color(SK_ColorBLACK); |
| 174 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); | 148 app_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 175 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); | 149 app_button->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 176 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight)); | 150 app_button->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); |
| 177 tmp_label->set_tag(i); | 151 app_button->set_tag(i); |
| 178 if (!app_info_[i].second.IsEmpty()) { | 152 if (!app_info_[i].second.IsEmpty()) { |
| 179 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, | 153 app_button->SetImage(views::ImageButton::STATE_NORMAL, |
| 180 *app_info_[i].second.ToImageSkia()); | 154 *app_info_[i].second.ToImageSkia()); |
| 181 } | 155 } |
| 182 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0)); | 156 app_button->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0)); |
| 183 scrollable_view->AddChildViewAt(tmp_label, i); | 157 scrollable_view->AddChildViewAt(app_button, i); |
| 184 } | 158 } |
| 185 | 159 |
| 186 scroll_view_ = new views::ScrollView(); | 160 scroll_view_ = new views::ScrollView(); |
| 187 scroll_view_->SetContents(scrollable_view); | 161 scroll_view_->SetContents(scrollable_view); |
| 188 // Setting a customized ScrollBar which is shown only when the mouse pointer | 162 // Setting a customized ScrollBar which is shown only when the mouse pointer |
| 189 // is inside the ScrollView. | 163 // is inside the ScrollView. |
| 190 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); | 164 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
| 191 // This part gives the scroll a fixed width and height. The height depends on | 165 // 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. | 166 // 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 | 167 // 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. | 168 // more than |kMaxAppResults| apps accessible by scrolling the list. |
| 195 if (app_info_.size() <= kMaxAppResults) { | 169 if (app_info_.size() <= kMaxAppResults) { |
| 196 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight); | 170 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight); |
| 197 } else { | 171 } else { |
| 198 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight); | 172 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight); |
| 199 } | 173 } |
| 200 AddChildView(scroll_view_); | 174 AddChildView(scroll_view_); |
| 201 | 175 |
| 202 // The lower part of the Picker contains only the 2 buttons | 176 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 203 // |just_once_button_| and |always_button_|. | 177 SetPaintToLayer(true); |
|
bruthig
2016/08/30 19:16:37
Why is this needed? Is it related to the InkDrop?
djacobo_
2016/09/06 23:21:23
I don't think it's related, I had some issues whil
| |
| 204 View* footer = new View(); | 178 layer()->SetMasksToBounds(true); |
| 205 footer->SetBorder(views::Border::CreateEmptyBorder(24, 0, 12, 12)); | 179 layer()->SetFillsBoundsOpaquely(false); |
| 206 views::BoxLayout* buttons_layout = new views::BoxLayout( | 180 } |
| 207 views::BoxLayout::kHorizontal, 0, 0, kButtonSeparation); | 181 } |
| 208 footer->SetLayoutManager(buttons_layout); | |
| 209 | 182 |
| 210 buttons_layout->set_main_axis_alignment( | 183 base::string16 IntentPickerBubbleView::GetWindowTitle() const { |
| 211 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 184 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_OPEN_WITH); |
| 212 footer->AddChildView(just_once_button_); | 185 } |
| 213 footer->AddChildView(always_button_); | 186 |
| 214 AddChildView(footer); | 187 base::string16 IntentPickerBubbleView::GetDialogButtonLabel( |
| 188 ui::DialogButton button) const { | |
| 189 if (button == ui::DIALOG_BUTTON_OK) | |
| 190 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE); | |
| 191 return l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS); | |
| 215 } | 192 } |
| 216 | 193 |
| 217 IntentPickerBubbleView::IntentPickerBubbleView( | 194 IntentPickerBubbleView::IntentPickerBubbleView( |
| 218 const std::vector<NameAndIcon>& app_info, | 195 const std::vector<NameAndIcon>& app_info, |
| 219 ThrottleCallback throttle_cb, | 196 ThrottleCallback throttle_cb, |
| 220 content::WebContents* web_contents) | 197 content::WebContents* web_contents) |
| 221 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, | 198 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, |
| 222 views::BubbleBorder::TOP_CENTER), | 199 views::BubbleBorder::TOP_CENTER), |
| 223 WebContentsObserver(web_contents), | 200 WebContentsObserver(web_contents), |
| 224 was_callback_run_(false), | |
| 225 throttle_cb_(throttle_cb), | 201 throttle_cb_(throttle_cb), |
| 226 selected_app_tag_(kAppTagNoneSelected), | 202 selected_app_tag_(kAppTagNoneSelected), |
| 227 always_button_(nullptr), | |
| 228 just_once_button_(nullptr), | |
| 229 scroll_view_(nullptr), | 203 scroll_view_(nullptr), |
| 230 app_info_(app_info) {} | 204 app_info_(app_info) {} |
| 231 | 205 |
| 232 IntentPickerBubbleView::~IntentPickerBubbleView() { | 206 IntentPickerBubbleView::~IntentPickerBubbleView() { |
| 233 SetLayoutManager(nullptr); | 207 SetLayoutManager(nullptr); |
| 234 } | 208 } |
| 235 | 209 |
| 236 // If the widget gets closed without an app being selected we still need to use | 210 // 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. | 211 // the callback so the caller can Resume the navigation. |
| 238 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { | 212 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { |
| 239 if (!was_callback_run_) { | 213 if (!throttle_cb_.is_null()) { |
| 240 throttle_cb_.Run( | 214 auto callback = throttle_cb_; |
| 241 kAppTagNoneSelected, | 215 throttle_cb_.Reset(); |
| 242 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); | 216 callback.Run(kAppTagNoneSelected, |
| 243 was_callback_run_ = true; | 217 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); |
| 244 } | 218 } |
| 245 } | 219 } |
| 246 | 220 |
| 247 int IntentPickerBubbleView::GetDialogButtons() const { | |
| 248 return ui::DIALOG_BUTTON_NONE; | |
| 249 } | |
| 250 | |
| 251 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, | 221 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, |
| 252 const ui::Event& event) { | 222 const ui::Event& event) { |
| 253 switch (sender->tag()) { | 223 // The selected app must be a value in the range [0, app_info_.size()-1]. |
| 254 case static_cast<int>(Option::ALWAYS): | 224 DCHECK(static_cast<size_t>(sender->tag()) < app_info_.size()); |
| 255 throttle_cb_.Run(selected_app_tag_, | 225 // The user cannot click on the |always_button_| or |just_once_button_| |
| 256 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | 226 // unless an explicit app has been selected. |
| 257 was_callback_run_ = true; | 227 if (selected_app_tag_ != kAppTagNoneSelected) |
| 258 GetWidget()->Close(); | 228 SetLabelButtonBackgroundColor(selected_app_tag_, SK_ColorWHITE); |
| 259 break; | 229 selected_app_tag_ = sender->tag(); |
| 260 case static_cast<int>(Option::JUST_ONCE): | 230 SetLabelButtonBackgroundColor(selected_app_tag_, |
| 261 throttle_cb_.Run( | 231 SkColorSetRGB(0xeb, 0xeb, 0xeb)); |
| 262 selected_app_tag_, | 232 GetDialogClientView()->UpdateDialogButtons(); |
| 263 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); | |
| 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 } | 233 } |
| 281 | 234 |
| 282 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { | 235 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { |
| 283 gfx::Size ps; | 236 gfx::Size ps; |
| 284 ps.set_width(kMaxWidth); | 237 ps.set_width(kMaxWidth); |
| 285 int apps_height = app_info_.size(); | 238 int apps_height = app_info_.size(); |
| 286 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so | 239 // 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. | 240 // the user can notice that more options are available. |
| 288 if (app_info_.size() > kMaxAppResults) { | 241 if (app_info_.size() > kMaxAppResults) { |
| 289 apps_height = (kMaxAppResults + 0.5) * kRowHeight; | 242 apps_height = (kMaxAppResults + 0.5) * kRowHeight; |
| 290 } else { | 243 } else { |
| 291 apps_height *= kRowHeight; | 244 apps_height *= kRowHeight; |
| 292 } | 245 } |
| 293 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); | 246 ps.set_height(apps_height); |
| 294 return ps; | 247 return ps; |
| 295 } | 248 } |
| 296 | 249 |
| 297 // If the actual web_contents gets destroyed in the middle of the process we | 250 // If the actual web_contents gets destroyed in the middle of the process we |
| 298 // should inform the caller about this error. | 251 // should inform the caller about this error. |
| 299 void IntentPickerBubbleView::WebContentsDestroyed() { | 252 void IntentPickerBubbleView::WebContentsDestroyed() { |
| 300 if (!was_callback_run_) { | 253 if (!throttle_cb_.is_null()) { |
| 301 throttle_cb_.Run(kAppTagNoneSelected, | 254 auto callback = throttle_cb_; |
| 302 arc::ArcNavigationThrottle::CloseReason::ERROR); | 255 throttle_cb_.Reset(); |
| 303 was_callback_run_ = true; | 256 callback.Run(kAppTagNoneSelected, |
| 257 arc::ArcNavigationThrottle::CloseReason::ERROR); | |
| 304 } | 258 } |
| 305 GetWidget()->Close(); | 259 GetWidget()->Close(); |
| 306 } | 260 } |
| 307 | 261 |
| 308 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { | 262 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { |
| 309 views::View* temp_contents = scroll_view_->contents(); | 263 views::View* temp_contents = scroll_view_->contents(); |
| 310 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); | 264 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); |
| 311 } | 265 } |
| 312 | 266 |
| 313 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, | 267 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, |
| 314 SkColor color) { | 268 SkColor color) { |
| 315 views::LabelButton* temp_lb = GetLabelButtonAt(index); | 269 views::LabelButton* button = GetLabelButtonAt(index); |
| 316 temp_lb->set_background(views::Background::CreateSolidBackground(color)); | 270 button->set_background(views::Background::CreateSolidBackground(color)); |
| 317 temp_lb->SchedulePaint(); | 271 button->SchedulePaint(); |
| 318 } | 272 } |
| 273 | |
| 274 // Method for testing, this way we don't need to expose IntentPickerMenuButton | |
| 275 gfx::ImageSkia IntentPickerBubbleView::GetAppImageForTesting(size_t index) { | |
| 276 return GetLabelButtonAt(index)->GetImage( | |
| 277 views::Button::ButtonState::STATE_NORMAL); | |
| 278 } | |
| OLD | NEW |