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