OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ |
7 | 7 |
| 8 #include "base/i18n/rtl.h" |
8 #include "content/public/browser/render_widget_host.h" | 9 #include "content/public/browser/render_widget_host.h" |
9 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
10 #include "ui/gfx/geometry/rect_f.h" | 11 #include "ui/gfx/geometry/rect_f.h" |
11 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 struct NativeWebKeyboardEvent; | 15 struct NativeWebKeyboardEvent; |
15 class RenderViewHost; | 16 class RenderViewHost; |
16 class WebContents; | 17 class WebContents; |
17 } | 18 } |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 class Display; | 21 class Display; |
21 } | 22 } |
22 | 23 |
23 namespace autofill { | 24 namespace autofill { |
24 | 25 |
25 // Class that controls common functionality for Autofill style popups. Can | 26 // Class that controls common functionality for Autofill style popups. Can |
26 // determine the correct location of a popup of a desired size and can register | 27 // determine the correct location of a popup of a desired size and can register |
27 // a handler to key press events. | 28 // a handler to key press events. |
28 class PopupControllerCommon { | 29 class PopupControllerCommon { |
29 public: | 30 public: |
30 PopupControllerCommon(const gfx::RectF& element_bounds, | 31 PopupControllerCommon(const gfx::RectF& element_bounds, |
| 32 base::i18n::TextDirection text_direction, |
31 gfx::NativeView container_view, | 33 gfx::NativeView container_view, |
32 content::WebContents* web_contents); | 34 content::WebContents* web_contents); |
33 virtual ~PopupControllerCommon(); | 35 virtual ~PopupControllerCommon(); |
34 | 36 |
35 const gfx::RectF& element_bounds() const { return element_bounds_; } | 37 const gfx::RectF& element_bounds() const { return element_bounds_; } |
| 38 bool is_rtl() const { return text_direction_ == base::i18n::RIGHT_TO_LEFT; } |
36 gfx::NativeView container_view() { return container_view_; } | 39 gfx::NativeView container_view() { return container_view_; } |
37 content::WebContents* web_contents() { return web_contents_; } | 40 content::WebContents* web_contents() { return web_contents_; } |
38 | 41 |
39 // Returns the enclosing rectangle for |element_bounds_|. | 42 // Returns the enclosing rectangle for |element_bounds_|. |
40 const gfx::Rect RoundedElementBounds() const; | 43 const gfx::Rect RoundedElementBounds() const; |
41 | 44 |
42 // Returns the bounds that the popup should be placed at, given the desired | 45 // Returns the bounds that the popup should be placed at, given the desired |
43 // width and height. By default this places the popup below |element_bounds| | 46 // width and height. By default this places the popup below |element_bounds| |
44 // but it will be placed above if there isn't enough space. | 47 // but it will be placed above if there isn't enough space. |
45 gfx::Rect GetPopupBounds(int desired_width, int desired_height) const; | 48 gfx::Rect GetPopupBounds(int desired_width, int desired_height) const; |
(...skipping 12 matching lines...) Expand all Loading... |
58 // RenderViewHost is the same as when it was originally registered. Safe to | 61 // RenderViewHost is the same as when it was originally registered. Safe to |
59 // call even if the callback is not currently registered. | 62 // call even if the callback is not currently registered. |
60 void RemoveKeyPressCallback(); | 63 void RemoveKeyPressCallback(); |
61 | 64 |
62 protected: | 65 protected: |
63 // A helper function to get the display closest to the given point (virtual | 66 // A helper function to get the display closest to the given point (virtual |
64 // for testing). | 67 // for testing). |
65 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const; | 68 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const; |
66 | 69 |
67 private: | 70 private: |
68 // Calculates the width of the popup and the x position of it. These values | |
69 // will stay on the screen. | |
70 std::pair<int, int> CalculatePopupXAndWidth( | 71 std::pair<int, int> CalculatePopupXAndWidth( |
71 const gfx::Display& left_display, | 72 const gfx::Display& left_display, |
72 const gfx::Display& right_display, | 73 const gfx::Display& right_display, |
73 int popup_required_width) const; | 74 int popup_required_width) const; |
74 | 75 |
75 // Calculates the height of the popup and the y position of it. These values | 76 // Calculates the height of the popup and the y position of it. These values |
76 // will stay on the screen. | 77 // will stay on the screen. |
77 std::pair<int, int> CalculatePopupYAndHeight( | 78 std::pair<int, int> CalculatePopupYAndHeight( |
78 const gfx::Display& top_display, | 79 const gfx::Display& top_display, |
79 const gfx::Display& bottom_display, | 80 const gfx::Display& bottom_display, |
80 int popup_required_height) const; | 81 int popup_required_height) const; |
81 | 82 |
82 // The bounds of the text element that is the focus of the popup. | 83 // The bounds of the text element that is the focus of the popup. |
83 // These coordinates are in screen space. | 84 // These coordinates are in screen space. |
84 gfx::RectF element_bounds_; | 85 gfx::RectF element_bounds_; |
85 | 86 |
| 87 // The direction of the <input>. |
| 88 base::i18n::TextDirection text_direction_; |
| 89 |
86 // Weak reference | 90 // Weak reference |
87 gfx::NativeView container_view_; | 91 gfx::NativeView container_view_; |
88 | 92 |
89 // The WebContents in which this object should listen for keyboard events | 93 // The WebContents in which this object should listen for keyboard events |
90 // while showing the popup. Can be NULL, in which case this object will not | 94 // while showing the popup. Can be NULL, in which case this object will not |
91 // listen for keyboard events. | 95 // listen for keyboard events. |
92 content::WebContents* web_contents_; | 96 content::WebContents* web_contents_; |
93 | 97 |
94 // The RenderViewHost that this object has registered its keyboard press | 98 // The RenderViewHost that this object has registered its keyboard press |
95 // callback with. | 99 // callback with. |
96 content::RenderViewHost* key_press_event_target_; | 100 content::RenderViewHost* key_press_event_target_; |
97 | 101 |
98 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; | 102 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; |
99 | 103 |
100 DISALLOW_COPY_AND_ASSIGN(PopupControllerCommon); | 104 DISALLOW_COPY_AND_ASSIGN(PopupControllerCommon); |
101 }; | 105 }; |
102 | 106 |
103 } // namespace autofill | 107 } // namespace autofill |
104 | 108 |
105 #endif // CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ | 109 #endif // CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ |
OLD | NEW |