OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_ |
6 #define CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_ | 6 #define CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_ |
7 | 7 |
8 #include "app/gfx/canvas.h" | 8 #include "app/gfx/canvas.h" |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "chrome/browser/extensions/extension_shelf_model.h" | 10 #include "chrome/browser/extensions/extension_shelf_model.h" |
11 #include "chrome/browser/extensions/extensions_service.h" | 11 #include "chrome/browser/extensions/extensions_service.h" |
12 #include "chrome/browser/views/browser_bubble.h" | 12 #include "chrome/browser/views/browser_bubble.h" |
13 #include "views/view.h" | 13 #include "views/view.h" |
14 | 14 |
15 class Browser; | 15 class Browser; |
16 namespace views { | 16 namespace views { |
17 class Label; | 17 class Label; |
18 class MouseEvent; | 18 class MouseEvent; |
19 } | 19 } |
20 | 20 |
21 // A shelf that contains Extension toolstrips. | 21 // A shelf that contains Extension toolstrips. |
22 class ExtensionShelf : public views::View, | 22 class ExtensionShelf : public views::View, |
23 public ExtensionContainer, | 23 public ExtensionContainer, |
24 public ExtensionShelfModelObserver { | 24 public ExtensionShelfModelObserver { |
25 public: | 25 public: |
26 explicit ExtensionShelf(Browser* browser); | 26 explicit ExtensionShelf(Browser* browser); |
27 virtual ~ExtensionShelf(); | 27 virtual ~ExtensionShelf(); |
28 | 28 |
29 // Get the current model. | 29 // Get the current model. |
30 ExtensionShelfModel* model() { return model_; } | 30 ExtensionShelfModel* model() { return model_.get(); } |
31 | 31 |
32 // View | 32 // View |
33 virtual void Paint(gfx::Canvas* canvas); | 33 virtual void Paint(gfx::Canvas* canvas); |
34 virtual gfx::Size GetPreferredSize(); | 34 virtual gfx::Size GetPreferredSize(); |
35 virtual void Layout(); | 35 virtual void Layout(); |
36 virtual void OnMouseExited(const views::MouseEvent& event); | 36 virtual void OnMouseExited(const views::MouseEvent& event); |
37 virtual void OnMouseEntered(const views::MouseEvent& event); | 37 virtual void OnMouseEntered(const views::MouseEvent& event); |
38 virtual bool GetAccessibleName(std::wstring* name); | 38 virtual bool GetAccessibleName(std::wstring* name); |
39 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); | 39 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); |
40 virtual void SetAccessibleName(const std::wstring& name); | 40 virtual void SetAccessibleName(const std::wstring& name); |
41 | 41 |
42 // ExtensionContainer | 42 // ExtensionContainer |
43 virtual void OnExtensionMouseEvent(ExtensionView* view); | 43 virtual void OnExtensionMouseEvent(ExtensionView* view); |
44 virtual void OnExtensionMouseLeave(ExtensionView* view); | 44 virtual void OnExtensionMouseLeave(ExtensionView* view); |
45 | 45 |
46 // ExtensionShelfModelObserver | 46 // ExtensionShelfModelObserver |
47 virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index); | 47 virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index); |
48 virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index); | 48 virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index); |
49 virtual void ToolstripDraggingFrom(ExtensionHost* toolstrip, int index); | 49 virtual void ToolstripDraggingFrom(ExtensionHost* toolstrip, int index); |
50 virtual void ToolstripMoved(ExtensionHost* toolstrip, | 50 virtual void ToolstripMoved(ExtensionHost* toolstrip, |
51 int from_index, | 51 int from_index, |
52 int to_index); | 52 int to_index); |
53 virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip); | 53 virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index); |
54 virtual void ExtensionShelfEmpty(); | 54 virtual void ExtensionShelfEmpty(); |
55 virtual void ShelfModelReloaded(); | 55 virtual void ShelfModelReloaded(); |
56 virtual void ShelfModelDeleting(); | |
57 | 56 |
58 protected: | 57 protected: |
59 // View | 58 // View |
60 virtual void ChildPreferredSizeChanged(View* child); | 59 virtual void ChildPreferredSizeChanged(View* child); |
61 | 60 |
62 private: | 61 private: |
63 class Toolstrip; | 62 class Toolstrip; |
64 friend class Toolstrip; | 63 friend class Toolstrip; |
65 class PlaceholderView; | 64 class PlaceholderView; |
66 | 65 |
67 // Dragging toolstrips | 66 // Dragging toolstrips |
68 void DropExtension(Toolstrip* handle, const gfx::Point& pt, bool cancel); | 67 void DropExtension(Toolstrip* handle, const gfx::Point& pt, bool cancel); |
69 | 68 |
70 // Expand the specified toolstrip, navigating to |url| if non-empty, | |
71 // and setting the |height|. | |
72 void ExpandToolstrip(ExtensionHost* host, const GURL& url, int height); | |
73 | |
74 // Collapse the specified toolstrip, navigating to |url| if non-empty. | |
75 void CollapseToolstrip(ExtensionHost* host, const GURL& url); | |
76 | |
77 // Inits the background bitmap. | 69 // Inits the background bitmap. |
78 void InitBackground(gfx::Canvas* canvas, const SkRect& subset); | 70 void InitBackground(gfx::Canvas* canvas, const SkRect& subset); |
79 | 71 |
80 // Returns the Toolstrip at |x| coordinate. If |x| is out of bounds, returns | 72 // Returns the Toolstrip at |x| coordinate. If |x| is out of bounds, returns |
81 // NULL. | 73 // NULL. |
82 Toolstrip* ToolstripAtX(int x); | 74 Toolstrip* ToolstripAtX(int x); |
83 | 75 |
84 // Returns the Toolstrip at |index|. | 76 // Returns the Toolstrip at |index|. |
85 Toolstrip* ToolstripAtIndex(int index); | 77 Toolstrip* ToolstripAtIndex(int index); |
86 | 78 |
87 // Returns the toolstrip associated with |view|. | 79 // Returns the toolstrip associated with |view|. |
88 Toolstrip* ToolstripForView(ExtensionView* view); | 80 Toolstrip* ToolstripForView(ExtensionView* view); |
89 | 81 |
90 // Loads initial state from |model_|. | 82 // Loads initial state from |model_|. |
91 void LoadFromModel(); | 83 void LoadFromModel(); |
92 | 84 |
93 // Background bitmap to draw under extension views. | 85 // Background bitmap to draw under extension views. |
94 SkBitmap background_; | 86 SkBitmap background_; |
95 | 87 |
96 // The model representing the toolstrips on the shelf. | 88 // The model representing the toolstrips on the shelf. |
97 ExtensionShelfModel* model_; | 89 scoped_ptr<ExtensionShelfModel> model_; |
98 | 90 |
99 // Storage of strings needed for accessibility. | 91 // Storage of strings needed for accessibility. |
100 std::wstring accessible_name_; | 92 std::wstring accessible_name_; |
101 | 93 |
102 DISALLOW_COPY_AND_ASSIGN(ExtensionShelf); | 94 DISALLOW_COPY_AND_ASSIGN(ExtensionShelf); |
103 }; | 95 }; |
104 | 96 |
105 #endif // CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_ | 97 #endif // CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_ |
OLD | NEW |