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 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // TODO(djacobo): Add a scroll bar and remove kMaxAppResults. | 29 // Using |kMaxAppResults| as a measure of how many apps we want to show. |
| 29 // Discriminating app results when the list is longer than |kMaxAppResults| | |
| 30 constexpr size_t kMaxAppResults = 3; | 30 constexpr size_t kMaxAppResults = 3; |
|
Yusuke Sato
2016/07/20 08:05:54
Please rebase this CL and use the throttle's.
djacobo_
2016/07/20 21:18:30
Done.
| |
| 31 // Main components sizes | 31 // Main components sizes |
| 32 constexpr int kRowHeight = 40; | 32 constexpr int kRowHeight = 40; |
| 33 constexpr int kMaxWidth = 320; | 33 constexpr int kMaxWidth = 320; |
| 34 constexpr int kHeaderHeight = 60; | 34 constexpr int kHeaderHeight = 60; |
| 35 constexpr int kFooterHeight = 68; | 35 constexpr int kFooterHeight = 68; |
| 36 // Inter components padding | 36 // Inter components padding |
| 37 constexpr int kButtonSeparation = 8; | 37 constexpr int kButtonSeparation = 8; |
| 38 constexpr int kLabelImageSeparation = 12; | 38 constexpr int kLabelImageSeparation = 12; |
| 39 | 39 |
| 40 // UI position wrt the Top Container | 40 // UI position wrt the Top Container |
| 41 constexpr int kTopContainerMerge = 3; | 41 constexpr int kTopContainerMerge = 3; |
| 42 constexpr int kAppTagNoneSelected = -1; | 42 constexpr size_t kAppTagNoneSelected = -1; |
| 43 | 43 |
| 44 // Arbitrary negative values to use as tags on the |always_button_| and | 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 | 45 // |just_once_button_|. These are negative to differentiate from the app's tags |
| 46 // which are always >= 0. | 46 // which are always >= 0. |
| 47 enum class Option : int { ALWAYS = -2, JUST_ONCE }; | 47 enum class Option : int { ALWAYS = -2, JUST_ONCE }; |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 void IntentPickerBubbleView::ShowBubble( | 52 void IntentPickerBubbleView::ShowBubble( |
| 53 content::NavigationHandle* handle, | 53 content::NavigationHandle* handle, |
| 54 const std::vector<NameAndIcon>& app_info, | 54 const std::vector<NameAndIcon>& app_info, |
| 55 const ThrottleCallback& throttle_cb) { | 55 const ThrottleCallback& throttle_cb) { |
| 56 Browser* browser = | 56 Browser* browser = |
| 57 chrome::FindBrowserWithWebContents(handle->GetWebContents()); | 57 chrome::FindBrowserWithWebContents(handle->GetWebContents()); |
| 58 if (!browser) { | 58 if (!browser) { |
| 59 throttle_cb.Run(kAppTagNoneSelected, | 59 throttle_cb.Run(kAppTagNoneSelected, |
| 60 arc::ArcNavigationThrottle::CloseReason::ERROR); | 60 arc::ArcNavigationThrottle::CloseReason::ERROR); |
| 61 return; | 61 return; |
| 62 } | 62 } |
| 63 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 63 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
| 64 if (!browser_view) { | 64 if (!browser_view) { |
| 65 throttle_cb.Run(kAppTagNoneSelected, | 65 throttle_cb.Run(kAppTagNoneSelected, |
| 66 arc::ArcNavigationThrottle::CloseReason::ERROR); | 66 arc::ArcNavigationThrottle::CloseReason::ERROR); |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 | 69 |
| 70 IntentPickerBubbleView* delegate = new IntentPickerBubbleView( | 70 IntentPickerBubbleView* delegate = new IntentPickerBubbleView( |
| 71 app_info, throttle_cb, handle->GetWebContents()); | 71 app_info, throttle_cb, handle->GetWebContents(), false); |
| 72 delegate->set_margins(gfx::Insets()); | 72 delegate->set_margins(gfx::Insets()); |
| 73 delegate->set_parent_window(browser_view->GetNativeWindow()); | 73 delegate->set_parent_window(browser_view->GetNativeWindow()); |
| 74 views::Widget* widget = | 74 views::Widget* widget = |
| 75 views::BubbleDialogDelegateView::CreateBubble(delegate); | 75 views::BubbleDialogDelegateView::CreateBubble(delegate); |
| 76 | 76 |
| 77 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 77 delegate->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 78 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 78 delegate->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 79 | 79 |
| 80 // Using the TopContainerBoundsInScreen Rect to specify an anchor for the the | 80 // Using the TopContainerBoundsInScreen Rect to specify an anchor for the the |
| 81 // UI. Rect allow us to set the coordinates(x,y), the width and height for the | 81 // UI. Rect allow us to set the coordinates(x,y), the width and height for the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS)); | 121 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_ALWAYS)); |
| 122 always_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 122 always_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 123 always_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); | 123 always_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); |
| 124 always_button_->set_tag(static_cast<int>(Option::ALWAYS)); | 124 always_button_->set_tag(static_cast<int>(Option::ALWAYS)); |
| 125 always_button_->SetMinSize(gfx::Size(80, 32)); | 125 always_button_->SetMinSize(gfx::Size(80, 32)); |
| 126 always_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); | 126 always_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); |
| 127 always_button_->SetTextColor(views::Button::STATE_NORMAL, button_text_color); | 127 always_button_->SetTextColor(views::Button::STATE_NORMAL, button_text_color); |
| 128 always_button_->SetTextColor(views::Button::STATE_HOVERED, button_text_color); | 128 always_button_->SetTextColor(views::Button::STATE_HOVERED, button_text_color); |
| 129 always_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 129 always_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 130 always_button_->SetState(views::Button::STATE_DISABLED); | 130 always_button_->SetState(views::Button::STATE_DISABLED); |
| 131 // Insets in the format top, left, bottom, right. | |
| 132 always_button_->SetBorder(views::Border::CreateEmptyBorder(16, 16, 16, 16)); | |
| 131 | 133 |
| 132 just_once_button_ = new views::LabelButton( | 134 just_once_button_ = new views::LabelButton( |
| 133 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE)); | 135 this, l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_JUST_ONCE)); |
| 134 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 136 just_once_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 135 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); | 137 just_once_button_->SetFontList(gfx::FontList("Roboto-medium, 13px")); |
| 136 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE)); | 138 just_once_button_->set_tag(static_cast<int>(Option::JUST_ONCE)); |
| 137 just_once_button_->SetMinSize(gfx::Size(80, 32)); | 139 just_once_button_->SetMinSize(gfx::Size(80, 32)); |
| 138 just_once_button_->SetState(views::Button::STATE_DISABLED); | 140 just_once_button_->SetState(views::Button::STATE_DISABLED); |
| 139 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); | 141 just_once_button_->SetTextColor(views::Button::STATE_DISABLED, SK_ColorGRAY); |
| 140 just_once_button_->SetTextColor(views::Button::STATE_NORMAL, | 142 just_once_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 141 button_text_color); | 143 button_text_color); |
| 142 just_once_button_->SetTextColor(views::Button::STATE_HOVERED, | 144 just_once_button_->SetTextColor(views::Button::STATE_HOVERED, |
| 143 button_text_color); | 145 button_text_color); |
| 144 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 146 just_once_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 147 just_once_button_->SetBorder( | |
| 148 views::Border::CreateEmptyBorder(16, 16, 16, 16)); | |
| 145 | 149 |
| 146 for (size_t i = 0; i < std::min(app_info_.size(), kMaxAppResults); ++i) { | 150 // Adding the |open_with| label to the picker. |
| 151 header_layout->StartRow(0, 0); | |
| 152 AddChildView(header); | |
| 153 | |
| 154 // Setting a view and a layout for a ScrollView for the apps' list. | |
| 155 views::View* scrollable_view = new views::View(); | |
| 156 views::BoxLayout* scrollable_layout = | |
| 157 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 158 scrollable_view->SetLayoutManager(scrollable_layout); | |
| 159 for (size_t i = 0; i < app_info_.size(); ++i) { | |
| 147 views::LabelButton* tmp_label = new views::LabelButton( | 160 views::LabelButton* tmp_label = new views::LabelButton( |
| 148 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); | 161 this, base::UTF8ToUTF16(base::StringPiece(app_info_[i].first))); |
| 149 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 162 tmp_label->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 150 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); | 163 tmp_label->SetFontList(gfx::FontList("Roboto-regular, 13px")); |
| 151 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); | 164 tmp_label->SetImageLabelSpacing(kLabelImageSeparation); |
| 152 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); | 165 tmp_label->SetMinSize(gfx::Size(kMaxWidth, kRowHeight)); |
| 153 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight)); | 166 tmp_label->SetMaxSize(gfx::Size(kMaxWidth, kRowHeight)); |
| 154 tmp_label->set_tag(i); | 167 tmp_label->set_tag(i); |
| 155 const gfx::ImageSkia* icon_ = app_info_[i].second.ToImageSkia(); | 168 if (!app_info_[i].second.IsEmpty()) { |
| 156 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, *icon_); | 169 tmp_label->SetImage(views::ImageButton::STATE_NORMAL, |
| 157 header_layout->StartRow(0, 0); | 170 *app_info_[i].second.ToImageSkia()); |
| 158 header_layout->AddView(tmp_label); | 171 } |
| 172 tmp_label->SetBorder(views::Border::CreateEmptyBorder(10, 16, 10, 0)); | |
| 173 app_label_ptr_.emplace_back(tmp_label); | |
| 174 scrollable_view->AddChildView(tmp_label); | |
| 159 } | 175 } |
| 160 | 176 |
| 161 // Adding the Upper part of the Intent Picker |open_with| label and all the | 177 views::ScrollView* scroll_view = new views::ScrollView(); |
| 162 // app options to |this|. | 178 scroll_view->SetContents(scrollable_view); |
| 163 header_layout->StartRow(0, 0); | 179 scroll_view->SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
| 164 header_layout->AddPaddingRow(0, 12); | 180 // This part gives the scroll a fixed width and height. The height depends on |
| 165 AddChildView(header); | 181 // how many app candidates we got and how many we actually want to show. |
| 182 if (app_info_.size() <= kMaxAppResults) { | |
| 183 scroll_view->ClipHeightTo(kMaxWidth, app_info_.size() * kRowHeight); | |
| 184 } else { | |
| 185 scroll_view->ClipHeightTo(kMaxWidth, (kMaxAppResults + 0.5) * kRowHeight); | |
|
Yusuke Sato
2016/07/19 10:23:58
Can you add a code comment to document why we need
djacobo_
2016/07/20 21:18:30
Done.
| |
| 186 } | |
| 187 AddChildView(scroll_view); | |
| 166 | 188 |
| 167 // The lower part of the Picker contains only the 2 buttons | 189 // The lower part of the Picker contains only the 2 buttons |
| 168 // |just_once_button_| and |always_button_|. | 190 // |just_once_button_| and |always_button_|. |
| 169 View* footer = new View(); | 191 View* footer = new View(); |
| 192 footer->SetBorder(views::Border::CreateEmptyBorder(24, 0, 12, 12)); | |
| 170 views::BoxLayout* buttons_layout = new views::BoxLayout( | 193 views::BoxLayout* buttons_layout = new views::BoxLayout( |
| 171 views::BoxLayout::kHorizontal, 12, 12, kButtonSeparation); | 194 views::BoxLayout::kHorizontal, 0, 0, kButtonSeparation); |
| 172 footer->SetLayoutManager(buttons_layout); | 195 footer->SetLayoutManager(buttons_layout); |
| 173 | 196 |
| 174 buttons_layout->set_main_axis_alignment( | 197 buttons_layout->set_main_axis_alignment( |
| 175 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 198 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
| 176 footer->AddChildView(just_once_button_); | 199 footer->AddChildView(just_once_button_); |
| 177 footer->AddChildView(always_button_); | 200 footer->AddChildView(always_button_); |
| 178 AddChildView(footer); | 201 AddChildView(footer); |
| 179 } | 202 } |
| 180 | 203 |
| 181 IntentPickerBubbleView::IntentPickerBubbleView( | 204 IntentPickerBubbleView::IntentPickerBubbleView( |
| 182 const std::vector<NameAndIcon>& app_info, | 205 const std::vector<NameAndIcon>& app_info, |
| 183 ThrottleCallback throttle_cb, | 206 ThrottleCallback throttle_cb, |
| 184 content::WebContents* web_contents) | 207 content::WebContents* web_contents, |
| 208 bool was_callback_run) | |
| 185 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, | 209 : views::BubbleDialogDelegateView(nullptr /* anchor_view */, |
| 186 views::BubbleBorder::TOP_CENTER), | 210 views::BubbleBorder::TOP_CENTER), |
| 187 WebContentsObserver(web_contents), | 211 WebContentsObserver(web_contents), |
| 188 was_callback_run_(false), | 212 was_callback_run_(was_callback_run), |
| 189 throttle_cb_(throttle_cb), | 213 throttle_cb_(throttle_cb), |
| 190 selected_app_tag_(kAppTagNoneSelected), | 214 selected_app_tag_(kAppTagNoneSelected), |
| 191 always_button_(nullptr), | 215 always_button_(nullptr), |
| 192 just_once_button_(nullptr), | 216 just_once_button_(nullptr), |
| 193 app_info_(app_info) {} | 217 app_info_(app_info) { |
| 218 app_label_ptr_.clear(); | |
|
Yusuke Sato
2016/07/19 10:23:58
std::vector is initially empty. please remove.
djacobo_
2016/07/20 21:18:30
Done.
| |
| 219 } | |
| 194 | 220 |
| 195 IntentPickerBubbleView::~IntentPickerBubbleView() { | 221 IntentPickerBubbleView::~IntentPickerBubbleView() { |
| 196 SetLayoutManager(nullptr); | 222 SetLayoutManager(nullptr); |
| 197 } | 223 } |
| 198 | 224 |
| 199 // If the widget gets closed without an app being selected we still need to use | 225 // 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. | 226 // the callback so the caller can Resume the navigation. |
| 201 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { | 227 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { |
| 202 if (!was_callback_run_) { | 228 if (!was_callback_run_) { |
| 203 throttle_cb_.Run( | 229 throttle_cb_.Run( |
| 204 kAppTagNoneSelected, | 230 kAppTagNoneSelected, |
| 205 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); | 231 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); |
| 206 was_callback_run_ = true; | 232 was_callback_run_ = true; |
| 207 } | 233 } |
| 208 } | 234 } |
| 209 | 235 |
| 210 int IntentPickerBubbleView::GetDialogButtons() const { | 236 int IntentPickerBubbleView::GetDialogButtons() const { |
| 211 return ui::DIALOG_BUTTON_NONE; | 237 return ui::DIALOG_BUTTON_NONE; |
| 212 } | 238 } |
| 213 | 239 |
| 214 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, | 240 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, |
| 215 const ui::Event& event) { | 241 const ui::Event& event) { |
| 216 switch (sender->tag()) { | 242 switch (sender->tag()) { |
| 217 case static_cast<int>(Option::ALWAYS): | 243 case static_cast<int>(Option::ALWAYS): |
| 218 throttle_cb_.Run(selected_app_tag_, | 244 if (!was_callback_run_) { |
|
Yusuke Sato
2016/07/19 10:23:58
What's wrong with running a cb for the unit tests?
djacobo_
2016/07/20 21:18:30
Yes, I will have a dummy method for receiving this
| |
| 219 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | 245 throttle_cb_.Run( |
| 220 was_callback_run_ = true; | 246 selected_app_tag_, |
| 247 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | |
| 248 was_callback_run_ = true; | |
| 249 } | |
| 221 GetWidget()->Close(); | 250 GetWidget()->Close(); |
| 222 break; | 251 break; |
| 223 case static_cast<int>(Option::JUST_ONCE): | 252 case static_cast<int>(Option::JUST_ONCE): |
| 224 throttle_cb_.Run( | 253 if (!was_callback_run_) { |
| 225 selected_app_tag_, | 254 throttle_cb_.Run( |
| 226 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); | 255 selected_app_tag_, |
| 227 was_callback_run_ = true; | 256 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); |
| 257 was_callback_run_ = true; | |
| 258 } | |
| 228 GetWidget()->Close(); | 259 GetWidget()->Close(); |
| 229 break; | 260 break; |
| 230 default: | 261 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_| | 262 // The user cannot click on the |always_button_| or |just_once_button_| |
| 234 // unless an explicit app has been selected. | 263 // unless an explicit app has been selected. |
| 264 if (selected_app_tag_ != kAppTagNoneSelected) { | |
| 265 app_label_ptr_[selected_app_tag_]->set_background( | |
| 266 views::Background::CreateSolidBackground(SK_ColorWHITE)); | |
| 267 app_label_ptr_[selected_app_tag_]->SchedulePaint(); | |
| 268 } | |
| 235 selected_app_tag_ = sender->tag(); | 269 selected_app_tag_ = sender->tag(); |
| 270 app_label_ptr_[selected_app_tag_]->set_background( | |
| 271 views::Background::CreateSolidBackground( | |
| 272 SkColorSetRGB(0xeb, 0xeb, 0xeb))); | |
| 236 always_button_->SetState(views::Button::STATE_NORMAL); | 273 always_button_->SetState(views::Button::STATE_NORMAL); |
| 237 just_once_button_->SetState(views::Button::STATE_NORMAL); | 274 just_once_button_->SetState(views::Button::STATE_NORMAL); |
| 238 } | 275 } |
| 239 } | 276 } |
| 240 | 277 |
| 241 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { | 278 gfx::Size IntentPickerBubbleView::GetPreferredSize() const { |
| 242 gfx::Size ps; | 279 gfx::Size ps; |
| 243 ps.set_width(kMaxWidth); | 280 ps.set_width(kMaxWidth); |
| 244 ps.set_height((std::min(app_info_.size(), kMaxAppResults)) * kRowHeight + | 281 int apps_height = app_info_.size(); |
| 245 kHeaderHeight + kFooterHeight); | 282 // We are showing |kMaxAppResults| + 0.5 rows at max, the extra 0.5 is used so |
| 283 // the user can notice that more options are available. | |
| 284 if (app_info_.size() > kMaxAppResults) { | |
| 285 apps_height = (kMaxAppResults + 0.5) * kRowHeight; | |
| 286 } else { | |
| 287 apps_height *= kRowHeight; | |
| 288 } | |
| 289 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); | |
| 246 return ps; | 290 return ps; |
| 247 } | 291 } |
| 248 | 292 |
| 249 // If the actual web_contents gets destroyed in the middle of the process we | 293 // If the actual web_contents gets destroyed in the middle of the process we |
| 250 // should inform the caller about this error. | 294 // should inform the caller about this error. |
| 251 void IntentPickerBubbleView::WebContentsDestroyed() { | 295 void IntentPickerBubbleView::WebContentsDestroyed() { |
| 252 if (!was_callback_run_) { | 296 if (!was_callback_run_) { |
| 253 throttle_cb_.Run(kAppTagNoneSelected, | 297 throttle_cb_.Run(kAppTagNoneSelected, |
| 254 arc::ArcNavigationThrottle::CloseReason::ERROR); | 298 arc::ArcNavigationThrottle::CloseReason::ERROR); |
| 255 was_callback_run_ = true; | 299 was_callback_run_ = true; |
| 256 } | 300 } |
| 257 GetWidget()->Close(); | 301 GetWidget()->Close(); |
| 258 } | 302 } |
| OLD | NEW |