summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/input_method
diff options
context:
space:
mode:
authornona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 16:08:38 +0000
committernona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 16:08:38 +0000
commita6824b43e73e73b75c2d2beb8c31611c493ffbcb (patch)
treee61510323a9bb2a9fd319a3a4bbe716627f66473 /chrome/browser/chromeos/input_method
parent4f9e5c83742590bd3d5549f0251b8ec60ff2e0c2 (diff)
downloadchromium_src-a6824b43e73e73b75c2d2beb8c31611c493ffbcb.zip
chromium_src-a6824b43e73e73b75c2d2beb8c31611c493ffbcb.tar.gz
chromium_src-a6824b43e73e73b75c2d2beb8c31611c493ffbcb.tar.bz2
Implement unittest for CandidateWindowView.
This is preparation for implementation Mozc suggest window fix. TEST=emerge chromeos-chrome and run unit_tests BUG=None Review URL: http://codereview.chromium.org/8573035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110492 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/input_method')
-rw-r--r--chrome/browser/chromeos/input_method/candidate_window.cc170
-rw-r--r--chrome/browser/chromeos/input_method/candidate_window_view.h186
-rw-r--r--chrome/browser/chromeos/input_method/candidate_window_view_unittest.cc123
3 files changed, 312 insertions, 167 deletions
diff --git a/chrome/browser/chromeos/input_method/candidate_window.cc b/chrome/browser/chromeos/input_method/candidate_window.cc
index 8c86be5..11bb276 100644
--- a/chrome/browser/chromeos/input_method/candidate_window.cc
+++ b/chrome/browser/chromeos/input_method/candidate_window.cc
@@ -16,6 +16,7 @@
#include "base/stringprintf.h"
#include "base/timer.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/chromeos/input_method/candidate_window_view.h"
#include "chrome/browser/chromeos/input_method/ibus_ui_controller.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -319,6 +320,8 @@ int ComputeAnnotationColumnWidth(const InputMethodLookupTable& lookup_table) {
return annotation_column_width;
}
+} // namespace
+
// HidableArea is used as an area to place optional information that can be
// turned displaying off if it is unnecessary.
class HidableArea : public views::View {
@@ -422,173 +425,6 @@ class InformationTextArea : public HidableArea {
DISALLOW_COPY_AND_ASSIGN(InformationTextArea);
};
-} // namespace
-
-class CandidateView;
-
-// CandidateWindowView is the main container of the candidate window UI.
-class CandidateWindowView : public views::View {
- public:
- // The object can be monitored by the observer.
- class Observer {
- public:
- virtual ~Observer() {}
- // The function is called when a candidate is committed.
- // See comments at NotifyCandidateClicked() in chromeos_input_method_ui.h
- // for details about the parameters.
- virtual void OnCandidateCommitted(int index, int button, int flag) = 0;
- };
-
- explicit CandidateWindowView(views::Widget* parent_frame);
- virtual ~CandidateWindowView() {}
- void Init();
-
- // Adds the given observer. The ownership is not transferred.
- void AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
- }
-
- // Removes the given observer.
- void RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
- }
-
- // Selects the candidate specified by the index in the current page
- // (zero-origin). Changes the appearance of the selected candidate,
- // updates the information in the candidate window as needed.
- void SelectCandidateAt(int index_in_page);
-
- // The function is called when a candidate is being dragged. From the
- // given point, locates the candidate under the mouse cursor, and
- // selects it.
- void OnCandidatePressed(const gfx::Point& point);
-
- // Commits the candidate currently being selected.
- void CommitCandidate();
-
- // Hides the lookup table.
- void HideLookupTable();
-
- // Hides the auxiliary text.
- void HideAuxiliaryText();
-
- // Hides the preedit text.
- void HidePreeditText();
-
- // Hides whole the candidate window.
- void HideAll();
-
- // Shows the lookup table.
- void ShowLookupTable();
-
- // Shows the auxiliary text.
- void ShowAuxiliaryText();
-
- // Shows the preedit text.
- void ShowPreeditText();
-
- // Updates the auxiliary text.
- void UpdateAuxiliaryText(const std::string& utf8_text);
-
- // Updates the preedit text.
- void UpdatePreeditText(const std::string& utf8_text);
-
- // Returns true if we should update candidate views in the window. For
- // instance, if we are going to show the same candidates as before, we
- // don't have to update candidate views. This happens when the user just
- // moves the cursor in the same page in the candidate window.
- bool ShouldUpdateCandidateViews(
- const InputMethodLookupTable& old_table,
- const InputMethodLookupTable& new_table);
-
- // Updates candidates of the candidate window from |lookup_table|.
- // Candidates are arranged per |orientation|.
- void UpdateCandidates(const InputMethodLookupTable& lookup_table);
-
- // Resizes and moves the parent frame. The two actions should be
- // performed consecutively as resizing may require the candidate window
- // to move. For instance, we may need to move the candidate window from
- // below the cursor to above the cursor, if the candidate window becomes
- // too big to be shown near the bottom of the screen. This function
- // needs to be called when the visible contents of the candidate window
- // are modified.
- void ResizeAndMoveParentFrame();
-
- // Returns the horizontal offset used for placing the vertical candidate
- // window so that the first candidate is aligned with the the text being
- // converted like:
- //
- // XXX <- The user is converting XXX
- // +-----+
- // |1 XXX|
- // |2 YYY|
- // |3 ZZZ|
- //
- // Returns 0 if no candidate is present.
- int GetHorizontalOffset();
-
- void set_cursor_location(const gfx::Rect& cursor_location) {
- cursor_location_ = cursor_location;
- }
-
- const gfx::Rect& cursor_location() const { return cursor_location_; }
-
- protected:
- // Override View::VisibilityChanged()
- virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE;
-
- // Override View::OnBoundsChanged()
- virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
-
- private:
- // Initializes the candidate views if needed.
- void MaybeInitializeCandidateViews(
- const InputMethodLookupTable& lookup_table);
-
- // Returns the appropriate area (header or footer) to put auxiliary texts.
- InformationTextArea* GetAuxiliaryTextArea();
-
- // The lookup table (candidates).
- InputMethodLookupTable lookup_table_;
-
- // The index in the current page of the candidate currently being selected.
- int selected_candidate_index_in_page_;
-
- // The observers of the object.
- ObserverList<Observer> observers_;
-
- // The parent frame.
- views::Widget* parent_frame_;
-
- // Views created in the class will be part of tree of |this|, so these
- // child views will be deleted when |this| is deleted.
-
- // The preedit area is where the preedit text is shown, if it is needed
- // in cases such as the focus is on a plugin that doesn't support in-line
- // preedit drawing.
- InformationTextArea* preedit_area_;
- // The header area is where the auxiliary text is shown, if the
- // orientation is horizontal. If the auxiliary text is not provided, we
- // show nothing. For instance, we show pinyin text like "zhong'guo".
- InformationTextArea* header_area_;
- // The candidate area is where candidates are rendered.
- HidableArea* candidate_area_;
- // The candidate views are used for rendering candidates.
- std::vector<CandidateView*> candidate_views_;
- // The footer area is where the auxiliary text is shown, if the
- // orientation is vertical. Usually the auxiliary text is used for
- // showing candidate number information like 2/19.
- InformationTextArea* footer_area_;
-
- // Current columns width in |candidate_area_|.
- int previous_shortcut_column_width_;
- int previous_candidate_column_width_;
- int previous_annotation_column_width_;
-
- // The last cursor location.
- gfx::Rect cursor_location_;
-};
-
// CandidateRow renderes a row of a candidate.
class CandidateView : public views::View {
public:
diff --git a/chrome/browser/chromeos/input_method/candidate_window_view.h b/chrome/browser/chromeos/input_method/candidate_window_view.h
new file mode 100644
index 0000000..05b593a
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/candidate_window_view.h
@@ -0,0 +1,186 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
+#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
+
+#include "chrome/browser/chromeos/input_method/ibus_ui_controller.h"
+#include "views/view.h"
+
+namespace chromeos {
+namespace input_method {
+
+class CandidateView;
+class InformationTextArea;
+class HidableArea;
+
+// CandidateWindowView is the main container of the candidate window UI.
+class CandidateWindowView : public views::View {
+ public:
+ // The object can be monitored by the observer.
+ class Observer {
+ public:
+ virtual ~Observer() {}
+ // The function is called when a candidate is committed.
+ // See comments at NotifyCandidateClicked() in chromeos_input_method_ui.h
+ // for details about the parameters.
+ virtual void OnCandidateCommitted(int index, int button, int flag) = 0;
+ };
+
+ explicit CandidateWindowView(views::Widget* parent_frame);
+ virtual ~CandidateWindowView() {}
+ void Init();
+
+ // Adds the given observer. The ownership is not transferred.
+ void AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+ }
+
+ // Removes the given observer.
+ void RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+ }
+
+ // Selects the candidate specified by the index in the current page
+ // (zero-origin). Changes the appearance of the selected candidate,
+ // updates the information in the candidate window as needed.
+ void SelectCandidateAt(int index_in_page);
+
+ // The function is called when a candidate is being dragged. From the
+ // given point, locates the candidate under the mouse cursor, and
+ // selects it.
+ void OnCandidatePressed(const gfx::Point& point);
+
+ // Commits the candidate currently being selected.
+ void CommitCandidate();
+
+ // Hides the lookup table.
+ void HideLookupTable();
+
+ // Hides the auxiliary text.
+ void HideAuxiliaryText();
+
+ // Hides the preedit text.
+ void HidePreeditText();
+
+ // Hides whole the candidate window.
+ void HideAll();
+
+ // Shows the lookup table.
+ void ShowLookupTable();
+
+ // Shows the auxiliary text.
+ void ShowAuxiliaryText();
+
+ // Shows the preedit text.
+ void ShowPreeditText();
+
+ // Updates the auxiliary text.
+ void UpdateAuxiliaryText(const std::string& utf8_text);
+
+ // Updates the preedit text.
+ void UpdatePreeditText(const std::string& utf8_text);
+
+ // Returns true if we should update candidate views in the window. For
+ // instance, if we are going to show the same candidates as before, we
+ // don't have to update candidate views. This happens when the user just
+ // moves the cursor in the same page in the candidate window.
+ static bool ShouldUpdateCandidateViews(
+ const InputMethodLookupTable& old_table,
+ const InputMethodLookupTable& new_table);
+
+ // Updates candidates of the candidate window from |lookup_table|.
+ // Candidates are arranged per |orientation|.
+ void UpdateCandidates(const InputMethodLookupTable& lookup_table);
+
+ // Resizes and moves the parent frame. The two actions should be
+ // performed consecutively as resizing may require the candidate window
+ // to move. For instance, we may need to move the candidate window from
+ // below the cursor to above the cursor, if the candidate window becomes
+ // too big to be shown near the bottom of the screen. This function
+ // needs to be called when the visible contents of the candidate window
+ // are modified.
+ void ResizeAndMoveParentFrame();
+
+ // Returns the horizontal offset used for placing the vertical candidate
+ // window so that the first candidate is aligned with the the text being
+ // converted like:
+ //
+ // XXX <- The user is converting XXX
+ // +-----+
+ // |1 XXX|
+ // |2 YYY|
+ // |3 ZZZ|
+ //
+ // Returns 0 if no candidate is present.
+ int GetHorizontalOffset();
+
+ void set_cursor_location(const gfx::Rect& cursor_location) {
+ cursor_location_ = cursor_location;
+ }
+
+ const gfx::Rect& cursor_location() const { return cursor_location_; }
+
+ protected:
+ // Override View::VisibilityChanged()
+ virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE;
+
+ // Override View::OnBoundsChanged()
+ virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
+
+ private:
+ // Initializes the candidate views if needed.
+ void MaybeInitializeCandidateViews(
+ const InputMethodLookupTable& lookup_table);
+
+ // Returns the appropriate area (header or footer) to put auxiliary texts.
+ InformationTextArea* GetAuxiliaryTextArea();
+
+ // The lookup table (candidates).
+ InputMethodLookupTable lookup_table_;
+
+ // The index in the current page of the candidate currently being selected.
+ int selected_candidate_index_in_page_;
+
+ // The observers of the object.
+ ObserverList<Observer> observers_;
+
+ // The parent frame.
+ views::Widget* parent_frame_;
+
+ // Views created in the class will be part of tree of |this|, so these
+ // child views will be deleted when |this| is deleted.
+
+ // The preedit area is where the preedit text is shown, if it is needed
+ // in cases such as the focus is on a plugin that doesn't support in-line
+ // preedit drawing.
+ InformationTextArea* preedit_area_;
+ // The header area is where the auxiliary text is shown, if the
+ // orientation is horizontal. If the auxiliary text is not provided, we
+ // show nothing. For instance, we show pinyin text like "zhong'guo".
+ InformationTextArea* header_area_;
+ // The candidate area is where candidates are rendered.
+ HidableArea* candidate_area_;
+ // The candidate views are used for rendering candidates.
+ std::vector<CandidateView*> candidate_views_;
+ // The footer area is where the auxiliary text is shown, if the
+ // orientation is vertical. Usually the auxiliary text is used for
+ // showing candidate number information like 2/19.
+ InformationTextArea* footer_area_;
+
+ // Current columns width in |candidate_area_|.
+ int previous_shortcut_column_width_;
+ int previous_candidate_column_width_;
+ int previous_annotation_column_width_;
+
+ // The last cursor location.
+ gfx::Rect cursor_location_;
+
+ DISALLOW_COPY_AND_ASSIGN(CandidateWindowView);
+};
+
+} // namespace input_method
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_CANDIDATE_WINDOW_VIEW_H_
diff --git a/chrome/browser/chromeos/input_method/candidate_window_view_unittest.cc b/chrome/browser/chromeos/input_method/candidate_window_view_unittest.cc
new file mode 100644
index 0000000..f3e62f9
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/candidate_window_view_unittest.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/input_method/candidate_window_view.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+namespace input_method {
+
+TEST(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) {
+ // This test verifies the process of judging update lookup-table or not.
+ // This judgement is handled by ShouldUpdateCandidateViews, which returns true
+ // if update is necessary and vice versa.
+ const char* kSampleCandidate1 = "Sample Candidate 1";
+ const char* kSampleCandidate2 = "Sample Candidate 2";
+ const char* kSampleCandidate3 = "Sample Candidate 3";
+
+ const char* kSampleAnnotation1 = "Sample Annotation 1";
+ const char* kSampleAnnotation2 = "Sample Annotation 2";
+ const char* kSampleAnnotation3 = "Sample Annotation 3";
+
+ const char* kSampleLabel1 = "Sample Label 1";
+ const char* kSampleLabel2 = "Sample Label 2";
+ const char* kSampleLabel3 = "Sample Label 3";
+
+ InputMethodLookupTable old_table;
+ InputMethodLookupTable new_table;
+
+ old_table.visible = true;
+ old_table.cursor_absolute_index = 0;
+ old_table.page_size = 1;
+ old_table.candidates.clear();
+ old_table.orientation = InputMethodLookupTable::kVertical;
+ old_table.labels.clear();
+ old_table.annotations.clear();
+
+ new_table = old_table;
+
+ EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+
+ new_table.visible = false;
+ // Visibility would be ignored.
+ EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table = old_table;
+ new_table.candidates.push_back(kSampleCandidate1);
+ old_table.candidates.push_back(kSampleCandidate1);
+ EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.labels.push_back(kSampleLabel1);
+ old_table.labels.push_back(kSampleLabel1);
+ EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.annotations.push_back(kSampleAnnotation1);
+ old_table.annotations.push_back(kSampleAnnotation1);
+ EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+
+ new_table.cursor_absolute_index = 1;
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table = old_table;
+
+ new_table.page_size = 2;
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table = old_table;
+
+ new_table.orientation = InputMethodLookupTable::kHorizontal;
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+
+ new_table = old_table;
+ new_table.candidates.push_back(kSampleCandidate2);
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ old_table.candidates.push_back(kSampleCandidate3);
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.candidates.clear();
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.candidates.push_back(kSampleCandidate2);
+ old_table.candidates.clear();
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+
+ new_table = old_table;
+ new_table.labels.push_back(kSampleLabel2);
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ old_table.labels.push_back(kSampleLabel3);
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.labels.clear();
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.labels.push_back(kSampleLabel2);
+ old_table.labels.clear();
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+
+ new_table = old_table;
+ new_table.annotations.push_back(kSampleAnnotation2);
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ old_table.annotations.push_back(kSampleAnnotation3);
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.annotations.clear();
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+ new_table.annotations.push_back(kSampleAnnotation2);
+ old_table.annotations.clear();
+ EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
+ new_table));
+}
+
+} // namespace input_method
+} // namespace chromeos