Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / controls / message_box_view.h
blobb56b3d112438955d0b8bc4bc06211f5c1b5b01bd
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_
8 #include <vector>
10 #include "base/strings/string16.h"
11 #include "ui/views/view.h"
13 namespace views {
15 class Checkbox;
16 class Label;
17 class Link;
18 class LinkListener;
19 class Textfield;
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 {
25 public:
26 enum Options {
27 NO_OPTIONS = 0,
28 // For a message from a web page (not from Chrome's UI), such as script
29 // dialog text, each paragraph's directionality is auto-detected using the
30 // directionality of the paragraph's first strong character's. Please refer
31 // to HTML5 spec for details.
32 // http://dev.w3.org/html5/spec/Overview.html#text-rendered-in-native-user-interfaces:
33 // The spec does not say anything about alignment. And we choose to
34 // align all paragraphs according to the direction of the first paragraph.
35 DETECT_DIRECTIONALITY = 1 << 0,
36 HAS_PROMPT_FIELD = 1 << 1,
39 struct VIEWS_EXPORT InitParams {
40 explicit InitParams(const base::string16& message);
41 ~InitParams();
43 uint16 options;
44 base::string16 message;
45 base::string16 default_prompt;
46 int message_width;
47 int inter_row_vertical_spacing;
50 explicit MessageBoxView(const InitParams& params);
52 virtual ~MessageBoxView();
54 // Returns the text box.
55 views::Textfield* text_box() { return prompt_field_; }
57 // Returns user entered data in the prompt field.
58 base::string16 GetInputText();
60 // Returns true if a checkbox is selected, false otherwise. (And false if
61 // the message box has no checkbox.)
62 bool IsCheckBoxSelected();
64 // Adds a checkbox with the specified label to the message box if this is the
65 // first call. Otherwise, it changes the label of the current checkbox. To
66 // start, the message box has no checkbox until this function is called.
67 void SetCheckBoxLabel(const base::string16& label);
69 // Sets the state of the check-box.
70 void SetCheckBoxSelected(bool selected);
72 // Sets the text and the listener of the link. If |text| is empty, the link
73 // is removed.
74 void SetLink(const base::string16& text, LinkListener* listener);
76 // View:
77 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
79 protected:
80 // View:
81 virtual void ViewHierarchyChanged(
82 const ViewHierarchyChangedDetails& details) OVERRIDE;
83 // Handles Ctrl-C and writes the message in the system clipboard.
84 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
86 private:
87 // Sets up the layout manager and initializes the message labels and prompt
88 // field. This should only be called once, from the constructor.
89 void Init(const InitParams& params);
91 // Sets up the layout manager based on currently initialized views. Should be
92 // called when a view is initialized or changed.
93 void ResetLayoutManager();
95 // Message for the message box.
96 std::vector<Label*> message_labels_;
98 // Input text field for the message box.
99 Textfield* prompt_field_;
101 // Checkbox for the message box.
102 Checkbox* checkbox_;
104 // Link displayed at the bottom of the view.
105 Link* link_;
107 // Maximum width of the message label.
108 int message_width_;
110 // Spacing between rows in the grid layout.
111 int inter_row_vertical_spacing_;
113 DISALLOW_COPY_AND_ASSIGN(MessageBoxView);
116 } // namespace views
118 #endif // UI_VIEWS_CONTROLS_MESSAGE_BOX_VIEW_H_