Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
|
Yusuke Sato
2016/08/17 23:18:21
Can you also mention that this CL adds the hoverin
| |
| 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 #ifndef CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" | 13 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/views/bubble/bubble_dialog_delegate.h" | 16 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 17 #include "ui/views/controls/button/button.h" | 17 #include "ui/views/controls/button/button.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 class NavigationHandle; | 20 class NavigationHandle; |
| 21 class WebContents; | 21 class WebContents; |
| 22 } // namespace content | 22 } // namespace content |
| 23 | 23 |
| 24 namespace views { | 24 namespace views { |
| 25 class Label; | 25 class Label; |
| 26 class LabelButton; | |
| 27 class View; | 26 class View; |
| 28 class Widget; | 27 class Widget; |
| 29 } // namespace views | 28 } // namespace views |
| 30 | 29 |
| 31 namespace ui { | 30 namespace ui { |
| 32 class Event; | 31 class Event; |
| 33 } // namespace ui | 32 } // namespace ui |
| 34 | 33 |
| 34 class IntentPickerMenuButton; | |
| 35 | |
| 35 // A bubble that displays a list of aplications (icons and names), after the | 36 // A bubble that displays a list of aplications (icons and names), after the |
| 36 // list we show a pair of buttons which allow the user to remember the selection | 37 // list we show a pair of buttons which allow the user to remember the selection |
| 37 // or not. This class comunicates the user's selection with a callback used by | 38 // or not. This class comunicates the user's selection with a callback used by |
| 38 // ArcNavigationThrottle. | 39 // ArcNavigationThrottle. |
| 39 // +--------------------------------+ | 40 // +--------------------------------+ |
| 40 // | Open with | | 41 // | Open with | |
| 41 // | | | 42 // | | |
| 42 // | Icon1 Name1 | | 43 // | Icon1 Name1 | |
| 43 // | Icon2 Name2 | | 44 // | Icon2 Name2 | |
| 44 // | ... | | 45 // | ... | |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 62 | 63 |
| 63 ~IntentPickerBubbleView() override; | 64 ~IntentPickerBubbleView() override; |
| 64 static void ShowBubble(content::NavigationHandle* handle, | 65 static void ShowBubble(content::NavigationHandle* handle, |
| 65 const std::vector<NameAndIcon>& app_info, | 66 const std::vector<NameAndIcon>& app_info, |
| 66 const ThrottleCallback& throttle_cb); | 67 const ThrottleCallback& throttle_cb); |
| 67 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView( | 68 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleView( |
| 68 const std::vector<NameAndIcon>& app_info, | 69 const std::vector<NameAndIcon>& app_info, |
| 69 const ThrottleCallback& throttle_cb, | 70 const ThrottleCallback& throttle_cb, |
| 70 content::WebContents* web_contents); | 71 content::WebContents* web_contents); |
| 71 | 72 |
| 73 // views::DialogDelegate overrides: | |
| 74 bool Accept() override; | |
| 75 bool Cancel() override; | |
| 76 bool Close() override; | |
| 77 int GetDefaultDialogButton() const override; | |
| 78 | |
| 72 protected: | 79 protected: |
| 73 // views::BubbleDialogDelegateView overrides: | 80 // views::BubbleDialogDelegateView overrides: |
| 74 void Init() override; | 81 void Init() override; |
| 75 | 82 |
| 83 // views::WidgetDelegate overrides: | |
| 84 base::string16 GetWindowTitle() const override; | |
| 85 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | |
| 86 | |
| 76 private: | 87 private: |
| 77 friend class IntentPickerBubbleViewTest; | 88 friend class IntentPickerBubbleViewTest; |
| 78 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons); | 89 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NullIcons); |
| 79 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons); | 90 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, NonNullIcons); |
| 80 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize); | 91 FRIEND_TEST_ALL_PREFIXES(IntentPickerBubbleViewTest, LabelsPtrVectorSize); |
| 81 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, | 92 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, |
| 82 ThrottleCallback throttle_cb, | 93 ThrottleCallback throttle_cb, |
| 83 content::WebContents* web_contents); | 94 content::WebContents* web_contents); |
| 84 | 95 |
| 85 // views::BubbleDialogDelegateView overrides: | 96 // views::BubbleDialogDelegateView overrides: |
| 86 void OnWidgetDestroying(views::Widget* widget) override; | 97 void OnWidgetDestroying(views::Widget* widget) override; |
| 87 int GetDialogButtons() const override; | 98 int GetDialogButtons() const override; |
| 88 | 99 |
| 89 // views::ButtonListener overrides: | 100 // views::ButtonListener overrides: |
| 90 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 101 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 91 | 102 |
| 92 // views::View overrides: | 103 // views::View overrides: |
| 93 gfx::Size GetPreferredSize() const override; | 104 gfx::Size GetPreferredSize() const override; |
| 94 | 105 |
| 95 // content::WebContentsObserver overrides: | 106 // content::WebContentsObserver overrides: |
| 96 void WebContentsDestroyed() override; | 107 void WebContentsDestroyed() override; |
| 97 | 108 |
| 98 // Retrieves the LabelButton* contained at position |index| from the internal | 109 // Retrieves the IntentPickerMenuButton* contained at position |index| from |
| 99 // ScrollView. | 110 // the internal ScrollView. |
| 100 views::LabelButton* GetLabelButtonAt(size_t index); | 111 IntentPickerMenuButton* GetIntentPickerMenuButtonAt(size_t index); |
| 101 void SetLabelButtonBackgroundColor(size_t index, SkColor color); | 112 void SetIntentPickerMenuButtonBackgroundColor(size_t index, SkColor color); |
| 113 gfx::ImageSkia GetAppImageForTesting(size_t index); | |
| 102 | 114 |
| 103 // Flag set to true iff the callback was Run at some previous step, used to | 115 // Flag set to true iff the callback was Run at some previous step, used to |
| 104 // ensure we only use the callback once. | 116 // ensure we only use the callback once. |
| 105 bool was_callback_run_; | 117 bool was_callback_run_; |
| 106 | 118 |
| 107 // Callback used to respond to ArcNavigationThrottle. | 119 // Callback used to respond to ArcNavigationThrottle. |
| 108 ThrottleCallback throttle_cb_; | 120 ThrottleCallback throttle_cb_; |
| 109 | 121 |
| 110 // Keeps a invalid value unless the user explicitly makes a decision. | 122 // Keeps a invalid value unless the user explicitly makes a decision. |
| 111 size_t selected_app_tag_; | 123 size_t selected_app_tag_; |
| 112 | 124 |
| 113 views::LabelButton* always_button_; | |
| 114 views::LabelButton* just_once_button_; | |
| 115 views::ScrollView* scroll_view_; | 125 views::ScrollView* scroll_view_; |
| 116 | 126 |
| 117 std::vector<NameAndIcon> app_info_; | 127 std::vector<NameAndIcon> app_info_; |
| 118 | 128 |
| 119 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); | 129 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); |
| 120 }; | 130 }; |
| 121 | 131 |
| 122 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ | 132 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ |
| OLD | NEW |