• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_CONTROLLER_IMPL_H_
7 
8 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
9 
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "chrome/browser/chromeos/input_method/candidate_window_view.h"
13 #include "chrome/browser/chromeos/input_method/infolist_window_view.h"
14 #include "ui/base/ime/chromeos/ibus_bridge.h"
15 
16 namespace views {
17 class Widget;
18 }  // namespace views
19 
20 namespace chromeos {
21 namespace input_method {
22 
23 class CandidateWindow;
24 class DelayableWidget;
25 class ModeIndicatorController;
26 
27 // The implementation of CandidateWindowController.
28 // CandidateWindowController controls the CandidateWindow.
29 class CandidateWindowControllerImpl
30     : public CandidateWindowController,
31       public CandidateWindowView::Observer,
32       public IBusPanelCandidateWindowHandlerInterface {
33  public:
34   CandidateWindowControllerImpl();
35   virtual ~CandidateWindowControllerImpl();
36 
37   // CandidateWindowController overrides:
38   virtual void AddObserver(
39       CandidateWindowController::Observer* observer) OVERRIDE;
40   virtual void RemoveObserver(
41       CandidateWindowController::Observer* observer) OVERRIDE;
42   virtual void Hide() OVERRIDE;
43 
44  protected:
45   // Returns infolist window position. This function handles right or bottom
46   // position overflow. Usually, infolist window is clipped with right-top of
47   // candidate window, but the position should be changed based on position
48   // overflow. If right of infolist window is out of screen, infolist window is
49   // shown left-top of candidate window. If bottom of infolist window is out of
50   // screen, infolist window is shown with clipping to bottom of screen.
51   // Infolist window does not overflow top and left direction.
52   static gfx::Point GetInfolistWindowPosition(
53       const gfx::Rect& candidate_window_rect,
54       const gfx::Rect& screen_rect,
55       const gfx::Size& infolist_winodw_size);
56 
57   // Converts |candidate_window| to infolist entries. |focused_index| become
58   // InfolistWindowView::InvalidFocusIndex if there is no selected entries.
59   static void ConvertLookupTableToInfolistEntry(
60       const CandidateWindow& candidate_window,
61       std::vector<InfolistWindowView::Entry>* infolist_entries,
62       size_t* focused_index);
63 
64   // Returns true if given |new_entries| is different from |old_entries| and
65   // should update current window.
66   static bool ShouldUpdateInfolist(
67       const std::vector<InfolistWindowView::Entry>& old_entries,
68       size_t old_focused_index,
69       const std::vector<InfolistWindowView::Entry>& new_entries,
70       size_t new_focused_index);
71 
72  private:
73   // CandidateWindowView::Observer implementation.
74   virtual void OnCandidateCommitted(int index) OVERRIDE;
75   virtual void OnCandidateWindowOpened() OVERRIDE;
76   virtual void OnCandidateWindowClosed() OVERRIDE;
77 
78   // Creates the candidate window view.
79   void CreateView();
80 
81   // IBusPanelCandidateWindowHandlerInterface overrides.
82   virtual void SetCursorBounds(const gfx::Rect& cursor_bounds,
83                                const gfx::Rect& composition_head) OVERRIDE;
84   virtual void UpdateAuxiliaryText(const std::string& utf8_text,
85                                    bool visible) OVERRIDE;
86   virtual void UpdateLookupTable(const CandidateWindow& candidate_window,
87                                  bool visible) OVERRIDE;
88   virtual void UpdatePreeditText(const std::string& utf8_text,
89                                  unsigned int cursor, bool visible) OVERRIDE;
90   virtual void FocusStateChanged(bool is_focused) OVERRIDE;
91 
92   // Updates infolist bounds, if current bounds is up-to-date, this function
93   // does nothing.
94   void UpdateInfolistBounds();
95 
96   // The candidate window view.
97   CandidateWindowView* candidate_window_view_;
98 
99   // This is the outer frame of the candidate window view. The frame will
100   // own |candidate_window_|.
101   scoped_ptr<views::Widget> frame_;
102 
103   // This is the outer frame of the infolist window view. The frame will
104   // own |infolist_window_|.
105   scoped_ptr<DelayableWidget> infolist_window_;
106 
107   // This is the controller of the IME mode indicator.
108   scoped_ptr<ModeIndicatorController> mode_indicator_controller_;
109 
110   // The infolist entries and its focused index which currently shown in
111   // Infolist window.
112   std::vector<InfolistWindowView::Entry> latest_infolist_entries_;
113   size_t latest_infolist_focused_index_;
114 
115   ObserverList<CandidateWindowController::Observer> observers_;
116 
117   DISALLOW_COPY_AND_ASSIGN(CandidateWindowControllerImpl);
118 };
119 
120 #endif  // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_CONTROLLER_IMPL_H_
121 
122 }  // namespace input_method
123 }  // namespace chromeos
124