OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 5 #ifndef UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
6 #define UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 6 #define UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | |
8 #include "ui/gfx/font.h" | 9 #include "ui/gfx/font.h" |
9 #include "ui/views/controls/button/button.h" | 10 #include "ui/views/controls/button/button.h" |
10 #include "ui/views/focus/focus_manager.h" | 11 #include "ui/views/focus/focus_manager.h" |
11 #include "ui/views/window/client_view.h" | 12 #include "ui/views/window/client_view.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 class DialogDelegate; | 16 class DialogDelegate; |
16 class NativeTextButton; | 17 class TextButton; |
17 class Widget; | 18 class Widget; |
18 namespace internal { | 19 namespace internal { |
19 class RootView; | 20 class RootView; |
20 } | 21 } |
21 | 22 |
22 /////////////////////////////////////////////////////////////////////////////// | 23 /////////////////////////////////////////////////////////////////////////////// |
23 // DialogClientView | 24 // DialogClientView |
24 // | 25 // |
25 // This ClientView subclass provides the content of a typical dialog box, | 26 // This ClientView subclass provides the content of a typical dialog box, |
26 // including a strip of buttons at the bottom right of the window, default | 27 // including a strip of buttons at the bottom right of the window, default |
27 // accelerator handlers for accept and cancel, and the ability for the | 28 // accelerator handlers for accept and cancel, and the ability for the |
28 // embedded contents view to provide extra UI to be shown in the row of | 29 // embedded contents view to provide extra UI to be shown in the row of |
29 // buttons. | 30 // buttons. |
30 // | 31 // |
31 // DialogClientView also provides the ability to set an arbitrary view that is | 32 // DialogClientView also provides the ability to set an arbitrary view that is |
32 // positioned beneath the buttons. | 33 // positioned beneath the buttons. |
33 // | 34 // |
34 class VIEWS_EXPORT DialogClientView : public ClientView, | 35 class VIEWS_EXPORT DialogClientView : public ClientView, |
35 public ButtonListener, | 36 public ButtonListener, |
36 public FocusChangeListener { | 37 public FocusChangeListener { |
37 public: | 38 public: |
38 DialogClientView(Widget* widget, View* contents_view); | 39 enum Style { |
Ben Goodger (Google)
2012/09/17 22:37:26
You should not need to add this.
Mike Wittman
2012/09/21 22:53:18
I've removed the enum in favor of accepting StyleP
| |
40 STYLE_NATIVE, | |
41 STYLE_WEB | |
42 }; | |
43 | |
44 DialogClientView(Widget* widget, View* contents_view, Style style); | |
39 virtual ~DialogClientView(); | 45 virtual ~DialogClientView(); |
40 | 46 |
41 // Adds the dialog buttons required by the supplied DialogDelegate to the | 47 // Adds the dialog buttons required by the supplied DialogDelegate to the |
42 // view. | 48 // view. |
43 void ShowDialogButtons(); | 49 void ShowDialogButtons(); |
44 | 50 |
45 // Updates the enabled state and label of the buttons required by the | 51 // Updates the enabled state and label of the buttons required by the |
46 // supplied DialogDelegate | 52 // supplied DialogDelegate |
47 void UpdateDialogButtons(); | 53 void UpdateDialogButtons(); |
48 | 54 |
49 // Accept the changes made in the window that contains this ClientView. | 55 // Accept the changes made in the window that contains this ClientView. |
50 void AcceptWindow(); | 56 void AcceptWindow(); |
51 | 57 |
52 // Cancel the changes made in the window that contains this ClientView. | 58 // Cancel the changes made in the window that contains this ClientView. |
53 void CancelWindow(); | 59 void CancelWindow(); |
54 | 60 |
55 // Accessors in case the user wishes to adjust these buttons. | 61 // Accessors in case the user wishes to adjust these buttons. |
56 NativeTextButton* ok_button() const { return ok_button_; } | 62 TextButton* ok_button() const { return ok_button_; } |
Ben Goodger (Google)
2012/09/17 22:37:26
This is OK.
| |
57 NativeTextButton* cancel_button() const { return cancel_button_; } | 63 TextButton* cancel_button() const { return cancel_button_; } |
58 | 64 |
59 // Overridden from View: | 65 // Overridden from View: |
60 virtual void NativeViewHierarchyChanged( | 66 virtual void NativeViewHierarchyChanged( |
61 bool attached, | 67 bool attached, |
62 gfx::NativeView native_view, | 68 gfx::NativeView native_view, |
63 internal::RootView* root_view) OVERRIDE; | 69 internal::RootView* root_view) OVERRIDE; |
64 | 70 |
65 // Overridden from ClientView: | 71 // Overridden from ClientView: |
66 virtual bool CanClose() OVERRIDE; | 72 virtual bool CanClose() OVERRIDE; |
67 virtual void WidgetClosing() OVERRIDE; | 73 virtual void WidgetClosing() OVERRIDE; |
68 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; | 74 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; |
69 virtual DialogClientView* AsDialogClientView() OVERRIDE; | 75 virtual DialogClientView* AsDialogClientView() OVERRIDE; |
70 virtual const DialogClientView* AsDialogClientView() const OVERRIDE; | 76 virtual const DialogClientView* AsDialogClientView() const OVERRIDE; |
71 | 77 |
72 // FocusChangeListener implementation: | 78 // FocusChangeListener implementation: |
73 virtual void OnWillChangeFocus(View* focused_before, | 79 virtual void OnWillChangeFocus(View* focused_before, |
74 View* focused_now) OVERRIDE; | 80 View* focused_now) OVERRIDE; |
75 virtual void OnDidChangeFocus(View* focused_before, | 81 virtual void OnDidChangeFocus(View* focused_before, |
76 View* focused_now) OVERRIDE; | 82 View* focused_now) OVERRIDE; |
77 | 83 |
78 protected: | 84 protected: |
79 // View overrides: | 85 // View overrides: |
80 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
81 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 86 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
82 virtual void Layout() OVERRIDE; | 87 virtual void Layout() OVERRIDE; |
83 virtual void ViewHierarchyChanged(bool is_add, View* parent, | 88 virtual void ViewHierarchyChanged(bool is_add, View* parent, |
84 View* child) OVERRIDE; | 89 View* child) OVERRIDE; |
85 virtual gfx::Size GetPreferredSize() OVERRIDE; | 90 virtual gfx::Size GetPreferredSize() OVERRIDE; |
86 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 91 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
87 | 92 |
88 // ButtonListener implementation: | 93 // ButtonListener implementation: |
89 virtual void ButtonPressed(Button* sender, | 94 virtual void ButtonPressed(Button* sender, |
90 const ui::Event& event) OVERRIDE; | 95 const ui::Event& event) OVERRIDE; |
91 | 96 |
92 private: | 97 private: |
98 struct StyleParams; | |
99 | |
100 // Create style parameter settings for the given style. | |
101 static StyleParams* CreateStyleParams(Style style); | |
102 | |
93 // Paint the size box in the bottom right corner of the window if it is | 103 // Paint the size box in the bottom right corner of the window if it is |
94 // resizable. | 104 // resizable. |
95 void PaintSizeBox(gfx::Canvas* canvas); | 105 void PaintSizeBox(gfx::Canvas* canvas); |
96 | 106 |
97 // Returns the width of the specified dialog button using the correct font. | 107 // Returns the width of the specified dialog button using the correct font. |
98 int GetButtonWidth(int button) const; | 108 int GetButtonWidth(int button) const; |
99 | 109 |
100 // Returns the greater of ok and cancel button's preferred height. | 110 // Returns the greater of ok and cancel button's preferred height. |
101 int GetButtonsHeight() const; | 111 int GetButtonsHeight() const; |
102 | 112 |
103 // Returns the height of the dialog buttons area, including the spacing | 113 // Returns the height of the dialog buttons area, including the spacing |
104 // between bottom of contents view and top of buttons, the buttons height, | 114 // between bottom of contents view and top of buttons, the buttons height, |
105 // and the spacing between bottom of buttons to end of the dialog. | 115 // and the spacing between bottom of buttons to end of the dialog. |
106 int GetDialogButtonsAreaHeight() const; | 116 int GetDialogButtonsAreaHeight() const; |
107 | 117 |
108 // Position and size various sub-views. | 118 // Position and size various sub-views. |
109 void LayoutDialogButtons(); | 119 void LayoutDialogButtons(); |
110 void LayoutContentsView(); | 120 void LayoutContentsView(); |
111 | 121 |
112 // Makes the specified button the default button. | 122 // Makes the specified button the default button. |
113 void SetDefaultButton(NativeTextButton* button); | 123 void SetDefaultButton(TextButton* button); |
114 | 124 |
115 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } | 125 bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } |
116 | 126 |
117 // Create and add the extra view, if supplied by the delegate. | 127 // Create and add the extra view, if supplied by the delegate. |
118 void CreateExtraView(); | 128 void CreateExtraView(); |
119 | 129 |
120 // Returns the DialogDelegate for the window. | 130 // Returns the DialogDelegate for the window. |
121 DialogDelegate* GetDialogDelegate() const; | 131 DialogDelegate* GetDialogDelegate() const; |
122 | 132 |
123 // Closes the widget. | 133 // Closes the widget. |
124 void Close(); | 134 void Close(); |
125 | 135 |
126 // Updates focus listener. | 136 // Updates focus listener. |
127 void UpdateFocusListener(); | 137 void UpdateFocusListener(); |
128 | 138 |
139 scoped_ptr<const StyleParams> style_params_; | |
140 | |
129 // The dialog buttons. | 141 // The dialog buttons. |
130 NativeTextButton* ok_button_; | 142 TextButton* ok_button_; |
131 NativeTextButton* cancel_button_; | 143 TextButton* cancel_button_; |
132 | 144 |
133 // The button that is currently the default button if any. | 145 // The button that is currently the default button if any. |
134 NativeTextButton* default_button_; | 146 TextButton* default_button_; |
135 | 147 |
136 // The button-level extra view, NULL unless the dialog delegate supplies one. | 148 // The button-level extra view, NULL unless the dialog delegate supplies one. |
137 View* extra_view_; | 149 View* extra_view_; |
138 | 150 |
139 // See description of DialogDelegate::GetSizeExtraViewHeightToButtons for | 151 // See description of DialogDelegate::GetSizeExtraViewHeightToButtons for |
140 // details on this. | 152 // details on this. |
141 bool size_extra_view_height_to_buttons_; | 153 bool size_extra_view_height_to_buttons_; |
142 | 154 |
143 // The layout rect of the size box, when visible. | 155 // The layout rect of the size box, when visible. |
144 gfx::Rect size_box_bounds_; | 156 gfx::Rect size_box_bounds_; |
145 | 157 |
146 // True if we've notified the delegate the window is closing and the delegate | 158 // True if we've notified the delegate the window is closing and the delegate |
147 // allosed the close. In some situations it's possible to get two closes (see | 159 // allosed the close. In some situations it's possible to get two closes (see |
148 // http://crbug.com/71940). This is used to avoid notifying the delegate | 160 // http://crbug.com/71940). This is used to avoid notifying the delegate |
149 // twice, which can have bad consequences. | 161 // twice, which can have bad consequences. |
150 bool notified_delegate_; | 162 bool notified_delegate_; |
151 | 163 |
152 // true if focus listener is added. | 164 // true if focus listener is added. |
153 bool listening_to_focus_; | 165 bool listening_to_focus_; |
154 | 166 |
155 // When ancestor gets changed focus manager gets changed as well. | 167 // When ancestor gets changed focus manager gets changed as well. |
156 FocusManager* saved_focus_manager_; | 168 FocusManager* saved_focus_manager_; |
157 | 169 |
158 DISALLOW_COPY_AND_ASSIGN(DialogClientView); | 170 DISALLOW_COPY_AND_ASSIGN(DialogClientView); |
159 }; | 171 }; |
160 | 172 |
161 } // namespace views | 173 } // namespace views |
162 | 174 |
163 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ | 175 #endif // UI_VIEWS_WINDOW_DIALOG_CLIENT_VIEW_H_ |
OLD | NEW |