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 #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 } // namespace content | 21 } // namespace content |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 class EventMonitor; | |
| 25 class Label; | 24 class Label; |
| 26 class LabelButton; | 25 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 |
| 35 // A bubble that displays a list of aplications (icons and names), after the | 34 // 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 | 35 // 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 | 36 // or not. This class comunicates the user's selection with a callback used by |
| 38 // ArcNavigationThrottle. | 37 // ArcNavigationThrottle. |
| 39 // +--------------------------------+ | 38 // +--------------------------------+ |
| 40 // | Open with | | 39 // | Open with | |
| 41 // | | | 40 // | | |
| 42 // | Icon1 Name1 | | 41 // | Icon1 Name1 | |
| 43 // | Icon2 Name2 | | 42 // | Icon2 Name2 | |
| 44 // | ... | | 43 // | ... | |
| 45 // | Icon(N) Name(N) | | 44 // | Icon(N) Name(N) | |
| 46 // | | | 45 // | | |
| 47 // | [JUST ONCE] [ALWAYS] | | 46 // | [JUST ONCE] [ALWAYS] | |
| 48 // +--------------------------------+ | 47 // +--------------------------------+ |
| 49 | 48 |
| 50 class IntentPickerBubbleView : public views::BubbleDialogDelegateView, | 49 class IntentPickerBubbleView : public views::BubbleDialogDelegateView, |
| 51 public views::ButtonListener, | 50 public views::ButtonListener, |
| 52 public content::WebContentsObserver { | 51 public content::WebContentsObserver { |
| 53 public: | 52 public: |
| 53 enum class ViewsId : int { | |
|
sky
2016/07/21 22:57:06
Move to private section, and add a comment.
djacobo_
2016/07/22 01:22:07
Done.
| |
| 54 HEADER = 0, | |
| 55 SCROLL_VIEW, | |
| 56 FOOTER, | |
| 57 }; | |
| 54 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; | 58 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; |
| 55 // This callback informs the index of the app selected by the user, along with | 59 // This callback informs the index of the app selected by the user, along with |
| 56 // the reason why the Bubble was closed. The size_t param must have a value in | 60 // the reason why the Bubble was closed. The size_t param must have a value in |
| 57 // the range [0, app_info.size()-1], except when the CloseReason is ERROR or | 61 // the range [0, app_info.size()-1], except when the CloseReason is ERROR or |
| 58 // DIALOG_DEACTIVATED, for these cases we return a dummy value | 62 // DIALOG_DEACTIVATED, for these cases we return a dummy value |
| 59 // |kAppTagNoneSelected| which won't be used at all and has no significance. | 63 // |kAppTagNoneSelected| which won't be used at all and has no significance. |
| 60 using ThrottleCallback = | 64 using ThrottleCallback = |
| 61 base::Callback<void(size_t, arc::ArcNavigationThrottle::CloseReason)>; | 65 base::Callback<void(size_t, arc::ArcNavigationThrottle::CloseReason)>; |
| 62 | 66 |
| 67 ~IntentPickerBubbleView() override; | |
| 63 static void ShowBubble(content::NavigationHandle* handle, | 68 static void ShowBubble(content::NavigationHandle* handle, |
| 64 const std::vector<NameAndIcon>& app_info, | 69 const std::vector<NameAndIcon>& app_info, |
| 65 const ThrottleCallback& throttle_cb); | 70 const ThrottleCallback& throttle_cb); |
| 71 static std::unique_ptr<IntentPickerBubbleView> CreateBubbleForTesting( | |
|
sky
2016/07/21 22:57:06
You're exposing 3 methods purely for testing. How
djacobo_
2016/07/22 01:22:07
We already did that on a previous version but opte
sky
2016/07/22 16:32:54
I prefer the friend and moving to test, otherwise
djacobo_
2016/07/22 22:37:24
Ok, got rid of the ForTesting() methods, I want to
| |
| 72 const std::vector<NameAndIcon>& app_info, | |
| 73 const ThrottleCallback& throttle_cb, | |
| 74 content::WebContents* web_contents); | |
| 75 size_t GetAppInfoSizeForTesting() const; | |
| 76 views::LabelButton* GetLabelButtonAtForTesting(size_t index); | |
| 66 | 77 |
| 67 protected: | 78 protected: |
| 68 // views::BubbleDialogDelegateView overrides: | 79 // views::BubbleDialogDelegateView overrides: |
| 69 void Init() override; | 80 void Init() override; |
| 70 | 81 |
| 71 private: | 82 private: |
| 72 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, | 83 IntentPickerBubbleView(const std::vector<NameAndIcon>& app_info, |
| 73 ThrottleCallback throttle_cb, | 84 ThrottleCallback throttle_cb, |
| 74 content::WebContents* web_contents); | 85 content::WebContents* web_contents); |
| 75 ~IntentPickerBubbleView() override; | |
| 76 | 86 |
| 77 // views::BubbleDialogDelegateView overrides: | 87 // views::BubbleDialogDelegateView overrides: |
| 78 void OnWidgetDestroying(views::Widget* widget) override; | 88 void OnWidgetDestroying(views::Widget* widget) override; |
| 79 int GetDialogButtons() const override; | 89 int GetDialogButtons() const override; |
| 80 | 90 |
| 81 // views::ButtonListener overrides: | 91 // views::ButtonListener overrides: |
| 82 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 92 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 83 | 93 |
| 84 // views::View overrides: | 94 // views::View overrides: |
| 85 gfx::Size GetPreferredSize() const override; | 95 gfx::Size GetPreferredSize() const override; |
| 86 | 96 |
| 87 // content::WebContentsObserver overrides: | 97 // content::WebContentsObserver overrides: |
| 88 void WebContentsDestroyed() override; | 98 void WebContentsDestroyed() override; |
| 89 | 99 |
| 100 views::LabelButton* GetLabelButtonAt(size_t index); | |
|
sky
2016/07/21 22:57:06
Add description.
djacobo_
2016/07/22 01:22:07
Done.
| |
| 101 void PaintLabelButton(size_t index, SkColor color); | |
|
sky
2016/07/21 22:57:06
Based on the name I thought this was called during
djacobo_
2016/07/22 01:22:07
Much better, thanks!. Done
| |
| 102 | |
| 90 // Flag set to true iff the callback was Run at some previous step, used to | 103 // Flag set to true iff the callback was Run at some previous step, used to |
| 91 // ensure we only use the callback once. | 104 // ensure we only use the callback once. |
| 92 bool was_callback_run_; | 105 bool was_callback_run_; |
| 93 | 106 |
| 94 // Callback used to respond to ArcNavigationThrottle. | 107 // Callback used to respond to ArcNavigationThrottle. |
| 95 ThrottleCallback throttle_cb_; | 108 ThrottleCallback throttle_cb_; |
| 96 | 109 |
| 97 // Keeps a invalid value unless the user explicitly makes a decision. | 110 // Keeps a invalid value unless the user explicitly makes a decision. |
| 98 size_t selected_app_tag_; | 111 size_t selected_app_tag_; |
| 99 | 112 |
| 100 views::LabelButton* always_button_; | 113 views::LabelButton* always_button_; |
| 101 views::LabelButton* just_once_button_; | 114 views::LabelButton* just_once_button_; |
| 102 | 115 |
| 103 std::vector<NameAndIcon> app_info_; | 116 std::vector<NameAndIcon> app_info_; |
| 104 | 117 |
| 105 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); | 118 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleView); |
| 106 }; | 119 }; |
| 107 | 120 |
| 108 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ | 121 #endif // CHROME_BROWSER_UI_VIEWS_INTENT_PICKER_BUBBLE_VIEW_H_ |
| OLD | NEW |