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 { | |
|
sky
2016/07/22 16:32:54
Why do you need the forward declaration here? If y
djacobo_
2016/07/22 22:37:25
Moving to the header, I think we needed the forwar
sky
2016/07/22 23:45:56
You must be inheriting it from someone else your p
djacobo_
2016/07/23 00:20:31
Yeah I agree, at least a subset of the trybots sho
| |
| 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 = static_cast<size_t>(-1); |
| 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 always_button_->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets(16))); | |
| 131 | 148 |
| 132 just_once_button_ = new views::LabelButton( | 149 just_once_button_ = new views::LabelButton( |
| 133 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE)); | 150 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE)); |
| 134 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 151 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 135 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); | 152 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); |
| 136 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE)); | 153 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE)); |
| 137 just_once_button_->SetMinSize(gfx::Size(80, 32)); | 154 just_once_button_->SetMinSize(gfx::Size(80, 32)); |
| 138 just_once_button_->SetState(views::Button::STATE_DISABLED); | 155 just_once_button_->SetState(views::Button::STATE_DISABLED); |
| 139 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); | 156 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); |
| 140 just_once_button_->SetTextColor(views::Button::STATE_NORMAL, | 157 just_once_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 141 button_text_color); | 158 button_text_color); |
| 142 just_once_button_->SetTextColor(views::Button::STATE_HOVERED, | 159 just_once_button_->SetTextColor(views::Button::STATE_HOVERED, |
| 143 button_text_color); | 160 button_text_color); |
| 144 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 161 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 162 just_once_button_->SetBorder( | |
| 163 views::Border::CreateEmptyBorder(gfx::Insets(16))); | |
| 145 | 164 |
| 146 for (size_t i = 0; i < std::min(app_info_.size(), kMaxAppResults); ++i) { | 165 header_layout->StartRow(0, 0); |
| 166 AddChildView(header); | |
| 167 | |
| 168 // Creates a view to hold the views for each app. | |
| 169 views::View* scrollable_view = new views::View(); | |
| 170 views::BoxLayout* scrollable_layout = | |
| 171 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 172 scrollable_view->SetLayoutManager(scrollable_layout); | |
| 173 for (size_t i = 0; i < app_info_.size(); ++i) { | |
| 147 views::LabelButton* tmp_label = new views::LabelButton( | 174 views::LabelButton* tmp_label = new views::LabelButton( |
| 148 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); | 175 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); |
| 149 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 176 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 150 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); | 177 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); |
| 151 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); | 178 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); |
| 152 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); | 179 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); |
| 153 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight)); | 180 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight)); |
| 154 tmp_label->set_tag(i); | 181 tmp_label->set_tag(i); |
| 155 const gfx::ImageSkia* icon_ = app_info_[i].second.ToImageSkia(); | 182 if (!app_info_[i].second.IsEmpty()) { |
| 156 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, *icon_); | 183 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, |
| 157 header_layout->StartRow(0, 0); | 184 *app_info_[i].second.ToImageSkia()); |
| 158 header_layout->AddView(tmp_label); | 185 } |
| 186 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0)); | |
| 187 scrollable_view->AddChildViewAt(tmp_label, i); | |
| 159 } | 188 } |
| 160 | 189 |
| 161 // Adding the Upper part of the Intent Picker |open_with| label and all the | 190 scroll_view_ = new views::ScrollView(); |
| 162 // app options to |this|. | 191 scroll_view_->SetContents(scrollable_view); |
| 163 header_layout->StartRow(0, 0); | 192 // Setting a customized ScrollBar which is shown only when the mouse pointer |
| 164 header_layout->AddPaddingRow(0, 12); | 193 // is inside the ScrollView. |
| 165 AddChildView(header); | 194 scroll_view_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
| 195 // This part gives the scroll a fixed width and height. The height depends on | |
| 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 | |
| 198 // more than |kMaxAppResults| apps accessible by scrolling the list. | |
| 199 if (app_info_.size() <= kMaxAppResults) { | |
| 200 scroll_view_->ClipHeightTo(kRowHeight, app_info_.size() * kRowHeight); | |
| 201 } else { | |
| 202 scroll_view_->ClipHeightTo(kRowHeight, (kMaxAppResults + 0.5) * kRowHeight); | |
| 203 } | |
| 204 AddChildView(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 AddChildView(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), |
| 233 scroll_view_(nullptr), | |
| 193 app_info_(app_info) {} | 234 app_info_(app_info) {} |
| 194 | 235 |
| 195 IntentPickerBubbleView::~IntentPickerBubbleView() { | 236 IntentPickerBubbleView::~IntentPickerBubbleView() { |
| 196 SetLayoutManager(nullptr); | 237 SetLayoutManager(nullptr); |
| 197 } | 238 } |
| 198 | 239 |
| 240 size_t IntentPickerBubbleView::GetAppInfoSizeForTesting() const { | |
| 241 return app_info_.size(); | |
| 242 } | |
| 243 | |
| 244 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAtForTesting( | |
| 245 size_t index) { | |
| 246 return GetLabelButtonAt(index); | |
| 247 } | |
| 248 | |
| 199 // If the widget gets closed without an app being selected we still need to use | 249 // 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. | 250 // the callback so the caller can Resume the navigation. |
| 201 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { | 251 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { |
| 202 if (!was_callback_run_) { | 252 if (!was_callback_run_) { |
| 203 throttle_cb_.Run( | 253 throttle_cb_.Run( |
| 204 kAppTagNoneSelected, | 254 kAppTagNoneSelected, |
| 205 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); | 255 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); |
| 206 was_callback_run_ = true; | 256 was_callback_run_ = true; |
| 207 } | 257 } |
| 208 } | 258 } |
| 209 | 259 |
| 210 int IntentPickerBubbleView::GetDialogButtons() const { | 260 int IntentPickerBubbleView::GetDialogButtons() const { |
| 211 return ui::DIALOG_BUTTON_NONE; | 261 return ui::DIALOG_BUTTON_NONE; |
| 212 } | 262 } |
| 213 | 263 |
| 214 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, | 264 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, |
| 215 const ui::Event& event) { | 265 const ui::Event& event) { |
| 216 switch (sender->tag()) { | 266 switch (sender->tag()) { |
| 217 case static_cast<int>(Option::ALWAYS): | 267 case static_cast<int>(Option::ALWAYS): |
| 218 throttle_cb_.Run(selected_app_tag_, | 268 if (!was_callback_run_) { |
| 219 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | 269 throttle_cb_.Run( |
| 220 was_callback_run_ = true; | 270 selected_app_tag_, |
| 271 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | |
| 272 was_callback_run_ = true; | |
| 273 } | |
| 221 GetWidget()->Close(); | 274 GetWidget()->Close(); |
| 222 break; | 275 break; |
| 223 case static_cast<int>(Option::JUST_ONCE): | 276 case static_cast<int>(Option::JUST_ONCE): |
| 224 throttle_cb_.Run( | 277 if (!was_callback_run_) { |
| 225 selected_app_tag_, | 278 throttle_cb_.Run( |
| 226 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); | 279 selected_app_tag_, |
| 227 was_callback_run_ = true; | 280 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); |
| 281 was_callback_run_ = true; | |
| 282 } | |
| 228 GetWidget()->Close(); | 283 GetWidget()->Close(); |
| 229 break; | 284 break; |
| 230 default: | 285 default: |
| 231 // TODO(djacobo): Paint the background of the selected button on a | 286 // Ignore the user's input if |sender->tag()| is not in the valid range. |
| 232 // different color, so the user has a clear remainder of his selection. | 287 if (static_cast<size_t>(sender->tag()) >= app_info_.size()) |
| 288 break; | |
| 233 // The user cannot click on the |always_button_| or |just_once_button_| | 289 // The user cannot click on the |always_button_| or |just_once_button_| |
| 234 // unless an explicit app has been selected. | 290 // unless an explicit app has been selected. |
| 291 if (selected_app_tag_ != kAppTagNoneSelected) | |
| 292 SetLabelButtonBackgroundColor(selected_app_tag_, SK_ColorWHITE); | |
| 235 selected_app_tag_ = sender->tag(); | 293 selected_app_tag_ = sender->tag(); |
| 294 SetLabelButtonBackgroundColor(selected_app_tag_, | |
| 295 SkColorSetRGB(0xeb, 0xeb, 0xeb)); | |
| 236 always_button_->SetState(views::Button::STATE_NORMAL); | 296 always_button_->SetState(views::Button::STATE_NORMAL); |
| 237 just_once_button_->SetState(views::Button::STATE_NORMAL); | 297 just_once_button_->SetState(views::Button::STATE_NORMAL); |
| 238 } | 298 } |
| 239 } | 299 } |
| 240 | 300 |
| 241 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { | 301 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { |
| 242 gfx::Size ps; | 302 gfx::Size ps; |
| 243 ps.set_width(kMaxWidth); | 303 ps.set_width(kMaxWidth); |
| 244 ps.set_height((std::min(app_info_.size(), kMaxAppResults)) * kRowHeight + | 304 int apps_height = app_info_.size(); |
| 245 kHeaderHeight + kFooterHeight); | 305 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so |
| 306 // the user can notice that more options are available. | |
| 307 if (app_info_.size() > kMaxAppResults) { | |
| 308 apps_height = (kMaxAppResults + 0.5) * kRowHeight; | |
| 309 } else { | |
| 310 apps_height *= kRowHeight; | |
| 311 } | |
| 312 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); | |
| 246 return ps; | 313 return ps; |
| 247 } | 314 } |
| 248 | 315 |
| 249 // If the actual web_contents gets destroyed in the middle of the process we | 316 // If the actual web_contents gets destroyed in the middle of the process we |
| 250 // should inform the caller about this error. | 317 // should inform the caller about this error. |
| 251 void IntentPickerBubbleView::WebContentsDestroyed() { | 318 void IntentPickerBubbleView::WebContentsDestroyed() { |
| 252 if (!was_callback_run_) { | 319 if (!was_callback_run_) { |
| 253 throttle_cb_.Run(kAppTagNoneSelected, | 320 throttle_cb_.Run(kAppTagNoneSelected, |
| 254 arc::ArcNavigationThrottle::CloseReason::ERROR); | 321 arc::ArcNavigationThrottle::CloseReason::ERROR); |
| 255 was_callback_run_ = true; | 322 was_callback_run_ = true; |
| 256 } | 323 } |
| 257 GetWidget()->Close(); | 324 GetWidget()->Close(); |
| 258 } | 325 } |
| 326 | |
| 327 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { | |
| 328 if (index >= app_info_.size()) | |
| 329 return nullptr; | |
| 330 views::View* temp_contents = scroll_view_->contents(); | |
| 331 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); | |
| 332 } | |
| 333 | |
| 334 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, | |
| 335 SkColor color) { | |
| 336 views::LabelButton* temp_lb = GetLabelButtonAt(index); | |
| 337 if (temp_lb == nullptr) | |
| 338 return; | |
| 339 temp_lb->set_background(views::Background::CreateSolidBackground(color)); | |
| 340 temp_lb->SchedulePaint(); | |
| 341 } | |
| OLD | NEW |