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 <algorithm> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/logging.h" | 8 #include "base/logging.h" |
| 11 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 13 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 16 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 17 #include "content/public/browser/navigation_handle.h" | 15 #include "content/public/browser/navigation_handle.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 19 #include "ui/views/border.h" | |
| 21 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
| 21 #include "ui/views/controls/scroll_view.h" | |
| 22 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | |
| 22 #include "ui/views/layout/box_layout.h" | 23 #include "ui/views/layout/box_layout.h" |
| 23 #include "ui/views/layout/grid_layout.h" | 24 #include "ui/views/layout/grid_layout.h" |
| 24 #include "ui/views/window/dialog_client_view.h" | 25 #include "ui/views/window/dialog_client_view.h" |
| 25 | 26 |
| 27 namespace content { | |
| 28 class WebContents; | |
| 29 } // namespace content | |
| 30 | |
| 26 namespace { | 31 namespace { |
| 27 | 32 |
| 28 // TODO(djacobo): Add a scroll bar and remove kMaxAppResults. | 33 // Using |kMaxAppResults| as a measure of how many apps we want to show. |
| 29 // Discriminating app results when the list is longer than |kMaxAppResults| | 34 constexpr size_t kMaxAppResults = arc::ArcNavigationThrottle::kMaxAppResults; |
| 30 constexpr size_t kMaxAppResults = 3; | |
| 31 // Main components sizes | 35 // Main components sizes |
| 32 constexpr int kRowHeight = 40; | 36 constexpr int kRowHeight = 40; |
| 33 constexpr int kMaxWidth = 320; | 37 constexpr int kMaxWidth = 320; |
| 34 constexpr int kHeaderHeight = 60; | 38 constexpr int kHeaderHeight = 60; |
| 35 constexpr int kFooterHeight = 68; | 39 constexpr int kFooterHeight = 68; |
| 36 // Inter components padding | 40 // Inter components padding |
| 37 constexpr int kButtonSeparation = 8; | 41 constexpr int kButtonSeparation = 8; |
| 38 constexpr int kLabelImageSeparation = 12; | 42 constexpr int kLabelImageSeparation = 12; |
| 39 | 43 |
| 40 // UI position wrt the Top Container | 44 // UI position wrt the Top Container |
| 41 constexpr int kTopContainerMerge = 3; | 45 constexpr int kTopContainerMerge = 3; |
| 42 constexpr int kAppTagNoneSelected = -1; | 46 constexpr size_t kAppTagNoneSelected = -1; |
|
Luis Héctor Chávez
2016/07/21 21:55:34
ok, just do an explicit cast: static_cast<size_t>(
djacobo_
2016/07/22 01:22:07
Done.
| |
| 43 | 47 |
| 44 // Arbitrary negative values to use as tags on the |always_button_| and | 48 // 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 | 49 // |just_once_button_|. These are negative to differentiate from the app's tags |
| 46 // which are always >= 0. | 50 // which are always >= 0. |
| 47 enum class Option : int { ALWAYS = -2, JUST_ONCE }; | 51 enum class Option : int { ALWAYS = -2, JUST_ONCE }; |
| 48 | 52 |
| 49 } // namespace | 53 } // namespace |
| 50 | 54 |
| 51 // static | 55 // static |
| 52 void IntentPickerBubbleView::ShowBubble( | 56 void IntentPickerBubbleView::ShowBubble( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 82 // new Rectangle. | 86 // new Rectangle. |
| 83 delegate->SetAnchorRect( | 87 delegate->SetAnchorRect( |
| 84 gfx::Rect(browser_view->GetTopContainerBoundsInScreen().x(), | 88 gfx::Rect(browser_view->GetTopContainerBoundsInScreen().x(), |
| 85 browser_view->GetTopContainerBoundsInScreen().y(), | 89 browser_view->GetTopContainerBoundsInScreen().y(), |
| 86 browser_view->GetTopContainerBoundsInScreen().width(), | 90 browser_view->GetTopContainerBoundsInScreen().width(), |
| 87 browser_view->GetTopContainerBoundsInScreen().height() - | 91 browser_view->GetTopContainerBoundsInScreen().height() - |
| 88 kTopContainerMerge)); | 92 kTopContainerMerge)); |
| 89 widget->Show(); | 93 widget->Show(); |
| 90 } | 94 } |
| 91 | 95 |
| 96 // static | |
| 97 std::unique_ptr<IntentPickerBubbleView> | |
| 98 IntentPickerBubbleView::CreateBubbleForTesting( | |
| 99 const std::vector<NameAndIcon>& app_info, | |
| 100 const ThrottleCallback& throttle_cb, | |
| 101 content::WebContents* web_contents) { | |
| 102 std::unique_ptr<IntentPickerBubbleView> bubble( | |
| 103 new IntentPickerBubbleView(app_info, throttle_cb, web_contents)); | |
| 104 bubble->Init(); | |
| 105 return bubble; | |
| 106 } | |
| 107 | |
| 92 void IntentPickerBubbleView::Init() { | 108 void IntentPickerBubbleView::Init() { |
| 93 SkColor button_text_color = SkColorSetRGB(0x42, 0x85, 0xf4); | 109 SkColor button_text_color = SkColorSetRGB(0x42, 0x85, 0xf4); |
| 94 | 110 |
| 95 views::BoxLayout* general_layout = | 111 views::BoxLayout* general_layout = |
| 96 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 112 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
| 97 SetLayoutManager(general_layout); | 113 SetLayoutManager(general_layout); |
| 98 | 114 |
| 99 // Create a view for the upper part of the UI, managed by a GridLayout to | 115 // Create a view for the upper part of the UI, managed by a GridLayout to |
| 100 // allow precise padding. | 116 // allow precise padding. |
| 101 View* header = new View(); | 117 View* header = new View(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 121 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS)); | 137 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS)); |
| 122 always_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 138 always_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 123 always_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); | 139 always_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); |
| 124 always_button_->set_tag(static_cast<int>(Option::ALWAYS)); | 140 always_button_->set_tag(static_cast<int>(Option::ALWAYS)); |
| 125 always_button_->SetMinSize(gfx::Size(80, 32)); | 141 always_button_->SetMinSize(gfx::Size(80, 32)); |
| 126 always_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); | 142 always_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); |
| 127 always_button_->SetTextColor(views::Button::STATE_NORMAL, button_text_color); | 143 always_button_->SetTextColor(views::Button::STATE_NORMAL, button_text_color); |
| 128 always_button_->SetTextColor(views::Button::STATE_HOVERED, button_text_color); | 144 always_button_->SetTextColor(views::Button::STATE_HOVERED, button_text_color); |
| 129 always_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 145 always_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 130 always_button_->SetState(views::Button::STATE_DISABLED); | 146 always_button_->SetState(views::Button::STATE_DISABLED); |
| 147 // Insets in the format top, left, bottom, right. | |
|
sky
2016/07/21 22:57:06
This comment isn't particularly useful when all th
djacobo_
2016/07/22 01:22:07
Nice shorthand, applied the same to |just_once_but
| |
| 148 always_button_->SetBorder(views::Border::CreateEmptyBorder(16, 16, 16, 16)); | |
| 131 | 149 |
| 132 just_once_button_ = new views::LabelButton( | 150 just_once_button_ = new views::LabelButton( |
| 133 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE)); | 151 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE)); |
| 134 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 152 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 135 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); | 153 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); |
| 136 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE)); | 154 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE)); |
| 137 just_once_button_->SetMinSize(gfx::Size(80, 32)); | 155 just_once_button_->SetMinSize(gfx::Size(80, 32)); |
| 138 just_once_button_->SetState(views::Button::STATE_DISABLED); | 156 just_once_button_->SetState(views::Button::STATE_DISABLED); |
| 139 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); | 157 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); |
| 140 just_once_button_->SetTextColor(views::Button::STATE_NORMAL, | 158 just_once_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 141 button_text_color); | 159 button_text_color); |
| 142 just_once_button_->SetTextColor(views::Button::STATE_HOVERED, | 160 just_once_button_->SetTextColor(views::Button::STATE_HOVERED, |
| 143 button_text_color); | 161 button_text_color); |
| 144 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 162 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 163 just_once_button_->SetBorder( | |
| 164 views::Border::CreateEmptyBorder(16, 16, 16, 16)); | |
| 145 | 165 |
| 146 for (size_t i = 0; i < std::min(app_info_.size(), kMaxAppResults); ++i) { | 166 // Adding the |open_with| label to the picker. |
|
sky
2016/07/21 22:57:06
Is this comment relevant here?
djacobo_
2016/07/22 01:22:07
I believe is easy to see what's going on by the co
| |
| 167 header_layout->StartRow(0, 0); | |
| 168 AddChildViewAt(header, static_cast<int>(ViewsId::HEADER)); | |
|
sky
2016/07/21 22:57:06
Based on the name I would expect ViewId to corresp
djacobo_
2016/07/22 01:22:07
You are right and the idea sounds better, modifica
| |
| 169 | |
| 170 // Setting a view and a layout for a ScrollView for the apps' list. | |
|
sky
2016/07/21 22:57:06
This comment is confusing. I think you mean someth
djacobo_
2016/07/22 01:22:07
Oh wow I messed up pretty badly indeed, Done.
| |
| 171 views::View* scrollable_view = new views::View(); | |
| 172 views::BoxLayout* scrollable_layout = | |
| 173 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 174 scrollable_view->SetLayoutManager(scrollable_layout); | |
| 175 for (size_t i = 0; i < app_info_.size(); ++i) { | |
| 147 views::LabelButton* tmp_label = new views::LabelButton( | 176 views::LabelButton* tmp_label = new views::LabelButton( |
| 148 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); | 177 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); |
| 149 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 178 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 150 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); | 179 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); |
| 151 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); | 180 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); |
| 152 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); | 181 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); |
| 153 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight)); | 182 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight)); |
| 154 tmp_label->set_tag(i); | 183 tmp_label->set_tag(i); |
| 155 const gfx::ImageSkia* icon_ = app_info_[i].second.ToImageSkia(); | 184 if (!app_info_[i].second.IsEmpty()) { |
| 156 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, *icon_); | 185 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, |
| 157 header_layout->StartRow(0, 0); | 186 *app_info_[i].second.ToImageSkia()); |
| 158 header_layout->AddView(tmp_label); | 187 } |
| 188 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0)); | |
| 189 scrollable_view->AddChildViewAt(tmp_label, i); | |
| 159 } | 190 } |
| 160 | 191 |
| 161 // Adding the Upper part of the Intent Picker |open_with| label and all the | 192 views::ScrollView* scroll_view = new views::ScrollView(); |
| 162 // app options to |this|. | 193 scroll_view->SetContents(scrollable_view); |
| 163 header_layout->StartRow(0, 0); | 194 scroll_view->SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
|
sky
2016/07/21 22:57:06
Is it really necessary to create an overlayscrollb
djacobo_
2016/07/22 01:22:07
Yes, I want the ScrollBar for this bubble to be sh
| |
| 164 header_layout->AddPaddingRow(0, 12); | 195 // This part gives the scroll a fixed width and height. The height depends on |
| 165 AddChildView(header); | 196 // how many app candidates we got and how many we actually want to show. |
| 197 // The added 0.5 on the else block allow us to let the user know there are | |
|
sky
2016/07/21 22:57:06
I don't understand the *.5. Why not just add 1 as
djacobo_
2016/07/22 01:22:07
What I was trying to say is, we are required to sh
sky
2016/07/22 16:32:54
My mistake, got it.
| |
| 198 // more than |kMaxAppResults| apps accessible by scrolling the list. | |
| 199 if (app_info_.size() <= kMaxAppResults) { | |
| 200 scroll_view->ClipHeightTo(kMaxWidth, app_info_.size() * kRowHeight); | |
|
sky
2016/07/21 22:57:06
The first argument is the min height, not a width.
djacobo_
2016/07/22 01:22:07
Totally misread the interface, moving to 1 Row at
| |
| 201 } else { | |
| 202 scroll_view->ClipHeightTo(kMaxWidth, (kMaxAppResults + 0.5) * kRowHeight); | |
| 203 } | |
| 204 AddChildViewAt(scroll_view, static_cast<int>(ViewsId::SCROLL_VIEW)); | |
| 166 | 205 |
| 167 // The lower part of the Picker contains only the 2 buttons | 206 // The lower part of the Picker contains only the 2 buttons |
| 168 // |just_once_button_| and |always_button_|. | 207 // |just_once_button_| and |always_button_|. |
| 169 View* footer = new View(); | 208 View* footer = new View(); |
| 209 footer->SetBorder(views::Border::CreateEmptyBorder(24, 0, 12, 12)); | |
| 170 views::BoxLayout* buttons_layout = new views::BoxLayout( | 210 views::BoxLayout* buttons_layout = new views::BoxLayout( |
| 171 views::BoxLayout::kHorizontal, 12, 12, kButtonSeparation); | 211 views::BoxLayout::kHorizontal, 0, 0, kButtonSeparation); |
| 172 footer->SetLayoutManager(buttons_layout); | 212 footer->SetLayoutManager(buttons_layout); |
| 173 | 213 |
| 174 buttons_layout->set_main_axis_alignment( | 214 buttons_layout->set_main_axis_alignment( |
| 175 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 215 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
| 176 footer->AddChildView(just_once_button_); | 216 footer->AddChildView(just_once_button_); |
| 177 footer->AddChildView(always_button_); | 217 footer->AddChildView(always_button_); |
| 178 AddChildView(footer); | 218 AddChildViewAt(footer, static_cast<int>(ViewsId::FOOTER)); |
| 179 } | 219 } |
| 180 | 220 |
| 181 IntentPickerBubbleView::IntentPickerBubbleView( | 221 IntentPickerBubbleView::IntentPickerBubbleView( |
| 182 const std::vector<NameAndIcon>& app_info, | 222 const std::vector<NameAndIcon>& app_info, |
| 183 ThrottleCallback throttle_cb, | 223 ThrottleCallback throttle_cb, |
| 184 content::WebContents* web_contents) | 224 content::WebContents* web_contents) |
| 185 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, | 225 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, |
| 186 views::BubbleBorder::TOP_CENTER), | 226 views::BubbleBorder::TOP_CENTER), |
| 187 WebContentsObserver(web_contents), | 227 WebContentsObserver(web_contents), |
| 188 was_callback_run_(false), | 228 was_callback_run_(false), |
| 189 throttle_cb_(throttle_cb), | 229 throttle_cb_(throttle_cb), |
| 190 selected_app_tag_(kAppTagNoneSelected), | 230 selected_app_tag_(kAppTagNoneSelected), |
| 191 always_button_(nullptr), | 231 always_button_(nullptr), |
| 192 just_once_button_(nullptr), | 232 just_once_button_(nullptr), |
| 193 app_info_(app_info) {} | 233 app_info_(app_info) {} |
| 194 | 234 |
| 195 IntentPickerBubbleView::~IntentPickerBubbleView() { | 235 IntentPickerBubbleView::~IntentPickerBubbleView() { |
| 196 SetLayoutManager(nullptr); | 236 SetLayoutManager(nullptr); |
| 197 } | 237 } |
| 198 | 238 |
| 239 size_t IntentPickerBubbleView::GetAppInfoSizeForTesting() const { | |
| 240 return app_info_.size(); | |
| 241 } | |
| 242 | |
| 243 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAtForTesting( | |
| 244 size_t index) { | |
| 245 return GetLabelButtonAt(index); | |
| 246 } | |
| 247 | |
| 199 // If the widget gets closed without an app being selected we still need to use | 248 // If the widget gets closed without an app being selected we still need to use |
| 200 // the callback so the caller can Resume the navigation. | 249 // the callback so the caller can Resume the navigation. |
| 201 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { | 250 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { |
| 202 if (!was_callback_run_) { | 251 if (!was_callback_run_) { |
| 203 throttle_cb_.Run( | 252 throttle_cb_.Run( |
| 204 kAppTagNoneSelected, | 253 kAppTagNoneSelected, |
| 205 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); | 254 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); |
| 206 was_callback_run_ = true; | 255 was_callback_run_ = true; |
| 207 } | 256 } |
| 208 } | 257 } |
| 209 | 258 |
| 210 int IntentPickerBubbleView::GetDialogButtons() const { | 259 int IntentPickerBubbleView::GetDialogButtons() const { |
| 211 return ui::DIALOG_BUTTON_NONE; | 260 return ui::DIALOG_BUTTON_NONE; |
| 212 } | 261 } |
| 213 | 262 |
| 214 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, | 263 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, |
| 215 const ui::Event& event) { | 264 const ui::Event& event) { |
| 216 switch (sender->tag()) { | 265 switch (sender->tag()) { |
| 217 case static_cast<int>(Option::ALWAYS): | 266 case static_cast<int>(Option::ALWAYS): |
| 218 throttle_cb_.Run(selected_app_tag_, | 267 if (!was_callback_run_) { |
|
sky
2016/07/21 22:57:06
Why do you need was_callback_run_?
djacobo_
2016/07/22 01:22:07
I don't want the callback being run twice since th
sky
2016/07/22 16:32:54
How can that happen? AFAICT the widget is closed o
djacobo_
2016/07/22 22:37:24
We can get rid of the if (!was_callback_run_) chec
sky
2016/07/22 23:45:56
That I understand. My question is solely about the
djacobo_
2016/07/23 00:20:31
Oh ok, we actually don't need it anymore. The thin
| |
| 219 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | 268 throttle_cb_.Run( |
| 220 was_callback_run_ = true; | 269 selected_app_tag_, |
| 270 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | |
| 271 was_callback_run_ = true; | |
| 272 } | |
| 221 GetWidget()->Close(); | 273 GetWidget()->Close(); |
| 222 break; | 274 break; |
| 223 case static_cast<int>(Option::JUST_ONCE): | 275 case static_cast<int>(Option::JUST_ONCE): |
| 224 throttle_cb_.Run( | 276 if (!was_callback_run_) { |
| 225 selected_app_tag_, | 277 throttle_cb_.Run( |
| 226 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); | 278 selected_app_tag_, |
| 227 was_callback_run_ = true; | 279 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); |
| 280 was_callback_run_ = true; | |
| 281 } | |
| 228 GetWidget()->Close(); | 282 GetWidget()->Close(); |
| 229 break; | 283 break; |
| 230 default: | 284 default: |
| 231 // TODO(djacobo): Paint the background of the selected button on a | |
| 232 // different color, so the user has a clear remainder of his selection. | |
| 233 // The user cannot click on the |always_button_| or |just_once_button_| | 285 // The user cannot click on the |always_button_| or |just_once_button_| |
| 234 // unless an explicit app has been selected. | 286 // unless an explicit app has been selected. |
| 287 if (selected_app_tag_ != kAppTagNoneSelected) | |
| 288 PaintLabelButton(selected_app_tag_, SK_ColorWHITE); | |
| 235 selected_app_tag_ = sender->tag(); | 289 selected_app_tag_ = sender->tag(); |
| 290 PaintLabelButton(selected_app_tag_, SkColorSetRGB(0xeb, 0xeb, 0xeb)); | |
| 236 always_button_->SetState(views::Button::STATE_NORMAL); | 291 always_button_->SetState(views::Button::STATE_NORMAL); |
| 237 just_once_button_->SetState(views::Button::STATE_NORMAL); | 292 just_once_button_->SetState(views::Button::STATE_NORMAL); |
| 238 } | 293 } |
| 239 } | 294 } |
| 240 | 295 |
| 241 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { | 296 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { |
| 242 gfx::Size ps; | 297 gfx::Size ps; |
| 243 ps.set_width(kMaxWidth); | 298 ps.set_width(kMaxWidth); |
| 244 ps.set_height((std::min(app_info_.size(), kMaxAppResults)) * kRowHeight + | 299 int apps_height = app_info_.size(); |
| 245 kHeaderHeight + kFooterHeight); | 300 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so |
| 301 // the user can notice that more options are available. | |
| 302 if (app_info_.size() > kMaxAppResults) { | |
| 303 apps_height = (kMaxAppResults + 0.5) * kRowHeight; | |
| 304 } else { | |
| 305 apps_height *= kRowHeight; | |
| 306 } | |
| 307 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); | |
| 246 return ps; | 308 return ps; |
| 247 } | 309 } |
| 248 | 310 |
| 249 // If the actual web_contents gets destroyed in the middle of the process we | 311 // If the actual web_contents gets destroyed in the middle of the process we |
| 250 // should inform the caller about this error. | 312 // should inform the caller about this error. |
| 251 void IntentPickerBubbleView::WebContentsDestroyed() { | 313 void IntentPickerBubbleView::WebContentsDestroyed() { |
| 252 if (!was_callback_run_) { | 314 if (!was_callback_run_) { |
| 253 throttle_cb_.Run(kAppTagNoneSelected, | 315 throttle_cb_.Run(kAppTagNoneSelected, |
| 254 arc::ArcNavigationThrottle::CloseReason::ERROR); | 316 arc::ArcNavigationThrottle::CloseReason::ERROR); |
| 255 was_callback_run_ = true; | 317 was_callback_run_ = true; |
| 256 } | 318 } |
| 257 GetWidget()->Close(); | 319 GetWidget()->Close(); |
| 258 } | 320 } |
| 321 | |
| 322 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { | |
| 323 int scroll_index = static_cast<int>(ViewsId::SCROLL_VIEW); | |
|
Luis Héctor Chávez
2016/07/21 21:55:34
Having the |selected_app_tag_| be a huge value is
djacobo_
2016/07/22 01:22:07
Done.
| |
| 324 views::ScrollView* temp_scroll = | |
| 325 static_cast<views::ScrollView*>(child_at(scroll_index)); | |
| 326 views::View* temp_contents = temp_scroll->contents(); | |
| 327 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); | |
| 328 } | |
| 329 | |
| 330 void IntentPickerBubbleView::PaintLabelButton(size_t index, SkColor color) { | |
| 331 views::LabelButton* temp_lb = GetLabelButtonAt(index); | |
| 332 temp_lb->set_background(views::Background::CreateSolidBackground(color)); | |
| 333 temp_lb->SchedulePaint(); | |
| 334 } | |
| OLD | NEW |