Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / ime / candidate_window_view.h
1 // Copyright 2014 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.
4
5 #ifndef ASH_IME_CANDIDATE_WINDOW_VIEW_H_
6 #define ASH_IME_CANDIDATE_WINDOW_VIEW_H_
7
8 #include "ash/ash_export.h"
9 #include "ui/base/ime/candidate_window.h"
10 #include "ui/views/bubble/bubble_delegate.h"
11 #include "ui/views/controls/button/button.h"
12
13 namespace ash {
14 namespace ime {
15
16 class CandidateView;
17 class InformationTextArea;
18
19 // CandidateWindowView is the main container of the candidate window UI.
20 class ASH_EXPORT CandidateWindowView : public views::BubbleDelegateView,
21                                        public views::ButtonListener {
22  public:
23   // The object can be monitored by the observer.
24   class Observer {
25    public:
26     virtual ~Observer() {}
27     // The function is called when a candidate is committed.
28     virtual void OnCandidateCommitted(int index) = 0;
29   };
30
31   explicit CandidateWindowView(gfx::NativeView parent);
32   virtual ~CandidateWindowView();
33   views::Widget* InitWidget();
34
35   // Adds the given observer. The ownership is not transferred.
36   void AddObserver(Observer* observer) {
37     observers_.AddObserver(observer);
38   }
39
40   // Removes the given observer.
41   void RemoveObserver(Observer* observer) {
42     observers_.RemoveObserver(observer);
43   }
44
45   // Hides the lookup table.
46   void HideLookupTable();
47
48   // Hides the auxiliary text.
49   void HideAuxiliaryText();
50
51   // Hides the preedit text.
52   void HidePreeditText();
53
54   // Shows the lookup table.
55   void ShowLookupTable();
56
57   // Shows the auxiliary text.
58   void ShowAuxiliaryText();
59
60   // Shows the preedit text.
61   void ShowPreeditText();
62
63   // Updates the preedit text.
64   void UpdatePreeditText(const base::string16& text);
65
66   // Updates candidates of the candidate window from |candidate_window|.
67   // Candidates are arranged per |orientation|.
68   void UpdateCandidates(const ui::CandidateWindow& candidate_window);
69
70   void SetCursorBounds(const gfx::Rect& cursor_bounds,
71                        const gfx::Rect& composition_head);
72
73  private:
74   friend class CandidateWindowViewTest;
75
76   // Overridden from views::ButtonListener:
77   virtual void ButtonPressed(views::Button* sender,
78                              const ui::Event& event) OVERRIDE;
79
80   void SelectCandidateAt(int index_in_page);
81   void UpdateVisibility();
82
83   // Initializes the candidate views if needed.
84   void MaybeInitializeCandidateViews(
85       const ui::CandidateWindow& candidate_window);
86
87   // The candidate window data model.
88   ui::CandidateWindow candidate_window_;
89
90   // The index in the current page of the candidate currently being selected.
91   int selected_candidate_index_in_page_;
92
93   // The observers of the object.
94   ObserverList<Observer> observers_;
95
96   // Views created in the class will be part of tree of |this|, so these
97   // child views will be deleted when |this| is deleted.
98   InformationTextArea* auxiliary_text_;
99   InformationTextArea* preedit_;
100   views::View* candidate_area_;
101
102   // The candidate views are used for rendering candidates.
103   std::vector<CandidateView*> candidate_views_;
104
105   // Current columns size in |candidate_area_|.
106   gfx::Size previous_shortcut_column_size_;
107   gfx::Size previous_candidate_column_size_;
108   gfx::Size previous_annotation_column_size_;
109
110   // The last cursor bounds.
111   gfx::Rect cursor_bounds_;
112
113   // The last compostion head bounds.
114   gfx::Rect composition_head_bounds_;
115
116   // True if the candidate window should be shown with aligning with composition
117   // text as opposed to the cursor.
118   bool should_show_at_composition_head_;
119
120   // True if the candidate window should be shonw on the upper side of
121   // composition text.
122   bool should_show_upper_side_;
123
124   // True if the candidate window was open.  This is used to determine when to
125   // send OnCandidateWindowOpened and OnCandidateWindowClosed events.
126   bool was_candidate_window_open_;
127
128   DISALLOW_COPY_AND_ASSIGN(CandidateWindowView);
129 };
130
131 }  // namespace ime
132 }  // namespace ash
133
134 #endif  // ASH_IME_CANDIDATE_WINDOW_VIEW_H_