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"
21 // This class displays the contents of a message box. It is intended for use
22 // within a constrained window, and has options for a message, prompt, OK
23 // and Cancel buttons.
24 class VIEWS_EXPORT MessageBoxView
: public View
{
26 // Internal class name.
27 static const char kViewClassName
[];
31 // For a message from a web page (not from Chrome's UI), such as script
32 // dialog text, each paragraph's directionality is auto-detected using the
33 // directionality of the paragraph's first strong character's. Please refer
34 // to HTML5 spec for details.
35 // http://dev.w3.org/html5/spec/Overview.html#text-rendered-in-native-user-interfaces:
36 // The spec does not say anything about alignment. And we choose to
37 // align all paragraphs according to the direction of the first paragraph.
38 DETECT_DIRECTIONALITY
= 1 << 0,
39 HAS_PROMPT_FIELD
= 1 << 1,
42 struct VIEWS_EXPORT InitParams
{
43 explicit InitParams(const base::string16
& message
);
47 base::string16 message
;
48 base::string16 default_prompt
;
50 int inter_row_vertical_spacing
;
53 explicit MessageBoxView(const InitParams
& params
);
55 ~MessageBoxView() override
;
57 // Returns the text box.
58 views::Textfield
* text_box() { return prompt_field_
; }
60 // Returns user entered data in the prompt field.
61 base::string16
GetInputText();
63 // Returns true if a checkbox is selected, false otherwise. (And false if
64 // the message box has no checkbox.)
65 bool IsCheckBoxSelected();
67 // Adds a checkbox with the specified label to the message box if this is the
68 // first call. Otherwise, it changes the label of the current checkbox. To
69 // start, the message box has no checkbox until this function is called.
70 void SetCheckBoxLabel(const base::string16
& label
);
72 // Sets the state of the check-box.
73 void SetCheckBoxSelected(bool selected
);
75 // Sets the text and the listener of the link. If |text| is empty, the link
77 void SetLink(const base::string16
& text
, LinkListener
* listener
);
80 void GetAccessibleState(ui::AXViewState
* state
) override
;
84 void ViewHierarchyChanged(
85 const ViewHierarchyChangedDetails
& details
) override
;
86 // Handles Ctrl-C and writes the message in the system clipboard.
87 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
88 const char* GetClassName() const override
;
91 // Sets up the layout manager and initializes the message labels and prompt
92 // field. This should only be called once, from the constructor.
93 void Init(const InitParams
& params
);
95 // Sets up the layout manager based on currently initialized views. Should be
96 // called when a view is initialized or changed.
97 void ResetLayoutManager();
99 // Message for the message box.
100 std::vector
<Label
*> message_labels_
;
102 // Input text field for the message box.
103 Textfield
* prompt_field_
;
105 // Checkbox for the message box.
108 // Link displayed at the bottom of the view.
111 // Maximum width of the message label.
114 // Spacing between rows in the grid layout.
115 int inter_row_vertical_spacing_
;
117 DISALLOW_COPY_AND_ASSIGN(MessageBoxView
);
122 #endif // UI_VIEWS_CONTROLS_MESSAGE_BOX_VIEW_H_