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 CHROME_BROWSER_CHROMEOS_INPUT_METHOD_UI_CANDIDATE_VIEW_H_ 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_UI_CANDIDATE_VIEW_H_ 7 8 #include "base/gtest_prod_util.h" 9 #include "base/macros.h" 10 #include "ui/base/ime/candidate_window.h" 11 #include "ui/chromeos/ui_chromeos_export.h" 12 #include "ui/views/controls/button/button.h" 13 #include "ui/views/controls/label.h" 14 #include "ui/views/view.h" 15 16 namespace ui { 17 namespace ime { 18 19 // CandidateView renderes a row of a candidate. 20 class UI_CHROMEOS_EXPORT CandidateView : public views::Button { 21 public: 22 CandidateView(PressedCallback callback, 23 ui::CandidateWindow::Orientation orientation); ~CandidateView()24 ~CandidateView() override {} 25 26 void GetPreferredWidths(int* shortcut_width, int* candidate_width); 27 28 void SetWidths(int shortcut_width, int candidate_width); 29 30 void SetEntry(const ui::CandidateWindow::Entry& entry); 31 32 // Sets infolist icon. 33 void SetInfolistIcon(bool enable); 34 35 void SetHighlighted(bool highlighted); 36 37 void SetPositionData(int index, int total); 38 39 private: 40 friend class CandidateWindowViewTest; 41 FRIEND_TEST_ALL_PREFIXES(CandidateWindowViewTest, ShortcutSettingTest); 42 43 // Overridden from views::Button: 44 void StateChanged(ButtonState old_state) override; 45 46 // Overridden from View: 47 const char* GetClassName() const override; 48 bool OnMouseDragged(const ui::MouseEvent& event) override; 49 void Layout() override; 50 gfx::Size CalculatePreferredSize() const override; 51 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; 52 53 // The orientation of the candidate view. 54 ui::CandidateWindow::Orientation orientation_; 55 56 // Views created in the class will be part of tree of |this|, so these 57 // child views will be deleted when |this| is deleted. 58 59 // The shortcut label renders shortcut numbers like 1, 2, and 3. 60 views::Label* shortcut_label_ = nullptr; 61 // The candidate label renders candidates. 62 views::Label* candidate_label_ = nullptr; 63 // The annotation label renders annotations. 64 views::Label* annotation_label_ = nullptr; 65 // The infolist icon. 66 views::View* infolist_icon_ = nullptr; 67 68 int shortcut_width_ = 0; 69 int candidate_width_ = 0; 70 bool highlighted_ = false; 71 72 // 0-based index of this candidate e.g. [0, total_candidates_ -1]. 73 int candidate_index_; 74 int total_candidates_; 75 76 DISALLOW_COPY_AND_ASSIGN(CandidateView); 77 }; 78 79 } // namespace ime 80 } // namespace ui 81 82 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_UI_CANDIDATE_VIEW_H_ 83