James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 5 | #ifndef ASH_SHELF_HOME_BUTTON_H_ |
| 6 | #define ASH_SHELF_HOME_BUTTON_H_ |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | |
Manu Cornet | 1ed1f6b | 2019-06-14 17:25:53 | [diff] [blame] | 10 | #include "ash/app_list/app_list_metrics.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 11 | #include "ash/ash_export.h" |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 12 | #include "ash/shelf/home_button_controller.h" |
Manu Cornet | 86aef98 | 2019-07-18 21:31:10 | [diff] [blame] | 13 | #include "ash/shelf/shelf_button_delegate.h" |
Manu Cornet | 40f90812 | 2018-11-08 23:15:25 | [diff] [blame] | 14 | #include "ash/shelf/shelf_control_button.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 15 | #include "base/macros.h" |
Ahmed Mehfooz | 6509620f | 2019-05-21 20:35:12 | [diff] [blame] | 16 | #include "ui/views/view_targeter_delegate.h" |
xiaohuic | fb5c54fc | 2017-06-28 17:32:02 | [diff] [blame] | 17 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 18 | namespace ash { |
Sammie Quon | 9b911f2f | 2017-12-15 02:53:15 | [diff] [blame] | 19 | |
Alex Newcomer | 030e706 | 2019-07-02 00:03:57 | [diff] [blame] | 20 | class ShelfButtonDelegate; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 21 | |
Michael Giuffrida | 01adeb07 | 2019-03-21 22:05:30 | [diff] [blame] | 22 | // Button used for the AppList icon on the shelf. It opens the app list (in |
| 23 | // clamshell mode) or home screen (in tablet mode). Because the clamshell-mode |
| 24 | // app list appears like a dismissable overlay, the button is highlighted while |
| 25 | // the app list is open in clamshell mode. |
| 26 | // |
| 27 | // If Assistant is enabled, the button is filled in; long-pressing it will |
| 28 | // launch Assistant. |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 29 | class ASH_EXPORT HomeButton : public ShelfControlButton, |
Manu Cornet | 86aef98 | 2019-07-18 21:31:10 | [diff] [blame] | 30 | public ShelfButtonDelegate, |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 31 | public views::ViewTargeterDelegate { |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 32 | public: |
Manu Cornet | c006633 | 2019-02-20 19:26:03 | [diff] [blame] | 33 | static const char kViewClassName[]; |
| 34 | |
Manu Cornet | 86aef98 | 2019-07-18 21:31:10 | [diff] [blame] | 35 | explicit HomeButton(Shelf* shelf); |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 36 | ~HomeButton() override; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 37 | |
Manu Cornet | e363aec | 2019-01-13 13:07:07 | [diff] [blame] | 38 | // views::Button: |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 39 | void OnGestureEvent(ui::GestureEvent* event) override; |
Manu Cornet | c006633 | 2019-02-20 19:26:03 | [diff] [blame] | 40 | const char* GetClassName() const override; |
Manu Cornet | e11c3c35 | 2019-07-31 06:13:41 | [diff] [blame] | 41 | base::string16 GetTooltipText(const gfx::Point& p) const override; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 42 | |
Manu Cornet | 86aef98 | 2019-07-18 21:31:10 | [diff] [blame] | 43 | // ShelfButtonDelegate: |
| 44 | void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button, |
| 45 | bool reverse) override; |
| 46 | void ButtonPressed(views::Button* sender, |
| 47 | const ui::Event& event, |
| 48 | views::InkDrop* ink_drop) override; |
Manu Cornet | 86aef98 | 2019-07-18 21:31:10 | [diff] [blame] | 49 | |
Michael Giuffrida | 01adeb07 | 2019-03-21 22:05:30 | [diff] [blame] | 50 | // Called when the availability of a long-press gesture may have changed, e.g. |
| 51 | // when Assistant becomes enabled. |
Yue Li | bcdb6aa | 2019-10-02 17:50:57 | [diff] [blame] | 52 | void OnAssistantAvailabilityChanged(); |
Michael Giuffrida | 01adeb07 | 2019-03-21 22:05:30 | [diff] [blame] | 53 | |
| 54 | // True if the app list is shown for the display containing this button. |
| 55 | bool IsShowingAppList() const; |
| 56 | |
Toni Barzic | 71ebb6fd | 2020-05-29 17:16:53 | [diff] [blame^] | 57 | // Called when a locale change is detected. Updates the button tooltip and |
| 58 | // accessible name. |
| 59 | void HandleLocaleChange(); |
Manu Cornet | 1ed1f6b | 2019-06-14 17:25:53 | [diff] [blame] | 60 | |
Alex Newcomer | 030e706 | 2019-07-02 00:03:57 | [diff] [blame] | 61 | // Returns the display which contains this view. |
| 62 | int64_t GetDisplayId() const; |
| 63 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 64 | protected: |
Manu Cornet | e363aec | 2019-01-13 13:07:07 | [diff] [blame] | 65 | // views::Button: |
Evan Stade | bad2bc6 | 2017-05-30 21:53:24 | [diff] [blame] | 66 | void PaintButtonContents(gfx::Canvas* canvas) override; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 67 | |
| 68 | private: |
Ahmed Mehfooz | 6509620f | 2019-05-21 20:35:12 | [diff] [blame] | 69 | // views::ViewTargeterDelegate: |
| 70 | bool DoesIntersectRect(const views::View* target, |
| 71 | const gfx::Rect& rect) const override; |
| 72 | |
Michael Giuffrida | 01adeb07 | 2019-03-21 22:05:30 | [diff] [blame] | 73 | // The controller used to determine the button's behavior. |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 74 | HomeButtonController controller_; |
Xiaohui Chen | 294e7bd | 2017-06-13 16:57:38 | [diff] [blame] | 75 | |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(HomeButton); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace ash |
| 80 | |
Manu Cornet | f953d49 | 2019-06-27 05:56:51 | [diff] [blame] | 81 | #endif // ASH_SHELF_HOME_BUTTON_H_ |