Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_ | |
| 7 | |
| 8 #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h" | |
| 9 #include "views/view.h" | |
| 10 | |
| 11 namespace chromeos { | |
| 12 namespace input_method { | |
| 13 | |
| 14 class CandidateView; | |
| 15 class InformationTextArea; | |
| 16 class HidableArea; | |
| 17 | |
| 18 // CandidateWindowView is the main container of the candidate window UI. | |
| 19 class CandidateWindowView : public views::View { | |
| 20 public: | |
| 21 // The object can be monitored by the observer. | |
| 22 class Observer { | |
| 23 public: | |
| 24 virtual ~Observer() {} | |
| 25 // The function is called when a candidate is committed. | |
| 26 // See comments at NotifyCandidateClicked() in chromeos_input_method_ui.h | |
| 27 // for details about the parameters. | |
| 28 virtual void OnCandidateCommitted(int index, int button, int flag) = 0; | |
| 29 }; | |
| 30 | |
| 31 explicit CandidateWindowView(views::Widget* parent_frame); | |
| 32 virtual ~CandidateWindowView() {} | |
| 33 void Init(); | |
| 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 // Selects the candidate specified by the index in the current page | |
| 46 // (zero-origin). Changes the appearance of the selected candidate, | |
| 47 // updates the information in the candidate window as needed. | |
| 48 void SelectCandidateAt(int index_in_page); | |
| 49 | |
| 50 // The function is called when a candidate is being dragged. From the | |
| 51 // given point, locates the candidate under the mouse cursor, and | |
| 52 // selects it. | |
| 53 void OnCandidatePressed(const gfx::Point& point); | |
| 54 | |
| 55 // Commits the candidate currently being selected. | |
| 56 void CommitCandidate(); | |
| 57 | |
| 58 // Hides the lookup table. | |
| 59 void HideLookupTable(); | |
| 60 | |
| 61 // Hides the auxiliary text. | |
| 62 void HideAuxiliaryText(); | |
| 63 | |
| 64 // Hides the preedit text. | |
| 65 void HidePreeditText(); | |
| 66 | |
| 67 // Hides whole the candidate window. | |
| 68 void HideAll(); | |
| 69 | |
| 70 // Shows the lookup table. | |
| 71 void ShowLookupTable(); | |
| 72 | |
| 73 // Shows the auxiliary text. | |
| 74 void ShowAuxiliaryText(); | |
| 75 | |
| 76 // Shows the preedit text. | |
| 77 void ShowPreeditText(); | |
| 78 | |
| 79 // Updates the auxiliary text. | |
| 80 void UpdateAuxiliaryText(const std::string& utf8_text); | |
| 81 | |
| 82 // Updates the preedit text. | |
| 83 void UpdatePreeditText(const std::string& utf8_text); | |
| 84 | |
| 85 // Returns true if we should update candidate views in the window. For | |
| 86 // instance, if we are going to show the same candidates as before, we | |
| 87 // don't have to update candidate views. This happens when the user just | |
| 88 // moves the cursor in the same page in the candidate window. | |
| 89 static bool ShouldUpdateCandidateViews( | |
| 90 const InputMethodLookupTable& old_table, | |
| 91 const InputMethodLookupTable& new_table); | |
| 92 | |
| 93 // Updates candidates of the candidate window from |lookup_table|. | |
| 94 // Candidates are arranged per |orientation|. | |
| 95 void UpdateCandidates(const InputMethodLookupTable& lookup_table); | |
| 96 | |
| 97 // Resizes and moves the parent frame. The two actions should be | |
| 98 // performed consecutively as resizing may require the candidate window | |
| 99 // to move. For instance, we may need to move the candidate window from | |
| 100 // below the cursor to above the cursor, if the candidate window becomes | |
| 101 // too big to be shown near the bottom of the screen. This function | |
| 102 // needs to be called when the visible contents of the candidate window | |
| 103 // are modified. | |
| 104 void ResizeAndMoveParentFrame(); | |
| 105 | |
| 106 // Returns the horizontal offset used for placing the vertical candidate | |
| 107 // window so that the first candidate is aligned with the the text being | |
| 108 // converted like: | |
| 109 // | |
| 110 // XXX <- The user is converting XXX | |
| 111 // +-----+ | |
| 112 // |1 XXX| | |
| 113 // |2 YYY| | |
| 114 // |3 ZZZ| | |
| 115 // | |
| 116 // Returns 0 if no candidate is present. | |
| 117 int GetHorizontalOffset(); | |
| 118 | |
| 119 void set_cursor_location(const gfx::Rect& cursor_location) { | |
| 120 cursor_location_ = cursor_location; | |
| 121 } | |
| 122 | |
| 123 const gfx::Rect& cursor_location() const { return cursor_location_; } | |
| 124 | |
| 125 protected: | |
| 126 // Override View::VisibilityChanged() | |
| 127 virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE; | |
| 128 | |
| 129 // Override View::OnBoundsChanged() | |
| 130 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | |
| 131 | |
| 132 private: | |
| 133 // Initializes the candidate views if needed. | |
| 134 void MaybeInitializeCandidateViews( | |
| 135 const InputMethodLookupTable& lookup_table); | |
| 136 | |
| 137 // Returns the appropriate area (header or footer) to put auxiliary texts. | |
| 138 InformationTextArea* GetAuxiliaryTextArea(); | |
| 139 | |
| 140 // The lookup table (candidates). | |
| 141 InputMethodLookupTable lookup_table_; | |
| 142 | |
| 143 // The index in the current page of the candidate currently being selected. | |
| 144 int selected_candidate_index_in_page_; | |
| 145 | |
| 146 // The observers of the object. | |
| 147 ObserverList<Observer> observers_; | |
| 148 | |
| 149 // The parent frame. | |
| 150 views::Widget* parent_frame_; | |
| 151 | |
| 152 // Views created in the class will be part of tree of |this|, so these | |
| 153 // child views will be deleted when |this| is deleted. | |
| 154 | |
| 155 // The preedit area is where the preedit text is shown, if it is needed | |
| 156 // in cases such as the focus is on a plugin that doesn't support in-line | |
| 157 // preedit drawing. | |
| 158 InformationTextArea* preedit_area_; | |
| 159 // The header area is where the auxiliary text is shown, if the | |
| 160 // orientation is horizontal. If the auxiliary text is not provided, we | |
| 161 // show nothing. For instance, we show pinyin text like "zhong'guo". | |
| 162 InformationTextArea* header_area_; | |
| 163 // The candidate area is where candidates are rendered. | |
| 164 HidableArea* candidate_area_; | |
| 165 // The candidate views are used for rendering candidates. | |
| 166 std::vector<CandidateView*> candidate_views_; | |
| 167 // The footer area is where the auxiliary text is shown, if the | |
| 168 // orientation is vertical. Usually the auxiliary text is used for | |
| 169 // showing candidate number information like 2/19. | |
| 170 InformationTextArea* footer_area_; | |
| 171 | |
| 172 // Current columns width in |candidate_area_|. | |
| 173 int previous_shortcut_column_width_; | |
| 174 int previous_candidate_column_width_; | |
| 175 int previous_annotation_column_width_; | |
| 176 | |
| 177 // The last cursor location. | |
| 178 gfx::Rect cursor_location_; | |
| 179 }; | |
|
Yusuke Sato
2011/11/17 06:07:39
one vertical space between 179 and 180
Yusuke Sato
2011/11/17 06:07:39
disallow copy and assign
Seigo Nonaka
2011/11/17 07:52:50
Done.
Seigo Nonaka
2011/11/17 07:52:50
Done.
| |
| 180 } // namespace input_method | |
| 181 } // namespace chromeos | |
| 182 | |
| 183 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_ | |
| OLD | NEW |