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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_CONTROLS_MESSAGE_BOX_VIEW_H_
6 #define UI_VIEWS_CONTROLS_MESSAGE_BOX_VIEW_H_
10 #include "base/strings/string16.h"
11 #include "ui/views/view.h"
26 // This class displays the contents of a message box. It is intended for use
27 // within a constrained window, and has options for a message, prompt, OK
28 // and Cancel buttons.
29 class VIEWS_EXPORT MessageBoxView
: public View
{
33 // For a message from a web page (not from Chrome's UI), such as script
34 // dialog text, each paragraph's directionality is auto-detected using the
35 // directionality of the paragraph's first strong character's. Please refer
36 // to HTML5 spec for details.
37 // http://dev.w3.org/html5/spec/Overview.html#text-rendered-in-native-user-interfaces:
38 // The spec does not say anything about alignment. And we choose to
39 // align all paragraphs according to the direction of the first paragraph.
40 DETECT_DIRECTIONALITY
= 1 << 0,
41 HAS_PROMPT_FIELD
= 1 << 1,
44 struct VIEWS_EXPORT InitParams
{
45 explicit InitParams(const base::string16
& message
);
49 base::string16 message
;
50 base::string16 default_prompt
;
52 int inter_row_vertical_spacing
;
55 explicit MessageBoxView(const InitParams
& params
);
57 virtual ~MessageBoxView();
59 // Returns the text box.
60 views::Textfield
* text_box() { return prompt_field_
; }
62 // Returns user entered data in the prompt field.
63 base::string16
GetInputText();
65 // Returns true if a checkbox is selected, false otherwise. (And false if
66 // the message box has no checkbox.)
67 bool IsCheckBoxSelected();
69 // Adds |icon| to the upper left of the message box or replaces the current
70 // icon. To start out, the message box has no icon.
71 void SetIcon(const gfx::ImageSkia
& icon
);
73 // Adds a checkbox with the specified label to the message box if this is the
74 // first call. Otherwise, it changes the label of the current checkbox. To
75 // start, the message box has no checkbox until this function is called.
76 void SetCheckBoxLabel(const base::string16
& label
);
78 // Sets the state of the check-box.
79 void SetCheckBoxSelected(bool selected
);
81 // Sets the text and the listener of the link. If |text| is empty, the link
83 void SetLink(const base::string16
& text
, LinkListener
* listener
);
86 virtual void GetAccessibleState(ui::AXViewState
* state
) OVERRIDE
;
90 virtual void ViewHierarchyChanged(
91 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
92 // Handles Ctrl-C and writes the message in the system clipboard.
93 virtual bool AcceleratorPressed(const ui::Accelerator
& accelerator
) OVERRIDE
;
96 // Sets up the layout manager and initializes the message labels and prompt
97 // field. This should only be called once, from the constructor.
98 void Init(const InitParams
& params
);
100 // Sets up the layout manager based on currently initialized views. Should be
101 // called when a view is initialized or changed.
102 void ResetLayoutManager();
104 // Message for the message box.
105 std::vector
<Label
*> message_labels_
;
107 // Input text field for the message box.
108 Textfield
* prompt_field_
;
110 // Icon displayed in the upper left corner of the message box.
113 // Checkbox for the message box.
116 // Link displayed at the bottom of the view.
119 // Maximum width of the message label.
122 // Spacing between rows in the grid layout.
123 int inter_row_vertical_spacing_
;
125 DISALLOW_COPY_AND_ASSIGN(MessageBoxView
);
130 #endif // UI_VIEWS_CONTROLS_MESSAGE_BOX_VIEW_H_