| 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 "base/i18n/rtl.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/public/browser/render_widget_host.h" | 10 #include "content/public/browser/render_widget_host.h" |
| 11 #include "ui/gfx/geometry/rect_f.h" | 11 #include "ui/gfx/geometry/rect_f.h" |
| 12 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 class RenderViewHost; | |
| 16 class WebContents; | 15 class WebContents; |
| 17 } | 16 } |
| 18 | 17 |
| 19 namespace autofill { | 18 namespace autofill { |
| 20 | 19 |
| 21 // Class that controls common functionality for Autofill style popups. Can | 20 // Class that controls common functionality for Autofill style popups. Can |
| 22 // determine the correct location of a popup of a desired size and can register | 21 // determine the correct location of a popup of a desired size and can register |
| 23 // a handler to key press events. | 22 // a handler to key press events. |
| 24 class PopupControllerCommon { | 23 class PopupControllerCommon { |
| 25 public: | 24 public: |
| 26 PopupControllerCommon(const gfx::RectF& element_bounds, | 25 PopupControllerCommon(const gfx::RectF& element_bounds, |
| 27 base::i18n::TextDirection text_direction, | 26 base::i18n::TextDirection text_direction, |
| 28 gfx::NativeView container_view, | 27 gfx::NativeView container_view, |
| 29 content::WebContents* web_contents); | 28 content::WebContents* web_contents); |
| 30 virtual ~PopupControllerCommon(); | 29 virtual ~PopupControllerCommon(); |
| 31 | 30 |
| 32 const gfx::RectF& element_bounds() const { return element_bounds_; } | 31 const gfx::RectF& element_bounds() const { return element_bounds_; } |
| 33 bool is_rtl() const { return text_direction_ == base::i18n::RIGHT_TO_LEFT; } | 32 bool is_rtl() const { return text_direction_ == base::i18n::RIGHT_TO_LEFT; } |
| 34 gfx::NativeView container_view() { return container_view_; } | 33 gfx::NativeView container_view() { return container_view_; } |
| 35 content::WebContents* web_contents() { return web_contents_; } | 34 content::WebContents* web_contents() { return web_contents_; } |
| 36 | 35 |
| 37 // Callback used to register with RenderViewHost. This can only be set once, | 36 // Callback used to register with RenderWidgetHost. This can only be set |
| 38 // or else a callback may be registered that will not be removed | 37 // once, or else a callback may be registered that will not be removed |
| 39 // (crbug.com/338070). Call will crash if callback is already set. | 38 // (crbug.com/338070). Call will crash if callback is already set. |
| 40 void SetKeyPressCallback(content::RenderWidgetHost::KeyPressEventCallback); | 39 void SetKeyPressCallback(content::RenderWidgetHost::KeyPressEventCallback); |
| 41 | 40 |
| 42 // Register listener for key press events with the current RenderViewHost | 41 // Register listener for key press events with the current RenderWidgetHost |
| 43 // associated with |web_contents_|. If callback has already been registered, | 42 // associated with focused frame in |web_contents_|. If callback has already |
| 44 // this has no effect. | 43 // been registered, this has no effect. |
| 45 void RegisterKeyPressCallback(); | 44 void RegisterKeyPressCallback(); |
| 46 | 45 |
| 47 // Remove previously registered callback, assuming that the current | 46 // Remove previously registered callback, assuming that the current |
| 48 // RenderViewHost is the same as when it was originally registered. Safe to | 47 // RenderWidgetHost is the same as when it was originally registered. Safe to |
| 49 // call even if the callback is not currently registered. | 48 // call even if the callback is not currently registered. |
| 50 void RemoveKeyPressCallback(); | 49 void RemoveKeyPressCallback(); |
| 51 | 50 |
| 52 private: | 51 private: |
| 53 // The bounds of the text element that is the focus of the popup. | 52 // The bounds of the text element that is the focus of the popup. |
| 54 // These coordinates are in screen space. | 53 // These coordinates are in screen space. |
| 55 gfx::RectF element_bounds_; | 54 gfx::RectF element_bounds_; |
| 56 | 55 |
| 57 // The direction of the <input>. | 56 // The direction of the <input>. |
| 58 base::i18n::TextDirection text_direction_; | 57 base::i18n::TextDirection text_direction_; |
| 59 | 58 |
| 60 // Weak reference | 59 // Weak reference |
| 61 gfx::NativeView container_view_; | 60 gfx::NativeView container_view_; |
| 62 | 61 |
| 63 // The WebContents in which this object should listen for keyboard events | 62 // The WebContents in which this object should listen for keyboard events |
| 64 // while showing the popup. Can be NULL, in which case this object will not | 63 // while showing the popup. Can be NULL, in which case this object will not |
| 65 // listen for keyboard events. | 64 // listen for keyboard events. |
| 66 content::WebContents* web_contents_; | 65 content::WebContents* web_contents_; |
| 67 | 66 |
| 68 // The RenderViewHost that this object has registered its keyboard press | 67 // The RenderWidgetHost that this object has registered its keyboard press |
| 69 // callback with. | 68 // callback with. |
| 70 content::RenderViewHost* key_press_event_target_; | 69 content::RenderWidgetHost* key_press_event_target_; |
| 71 | 70 |
| 72 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; | 71 content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_; |
| 73 | 72 |
| 74 DISALLOW_COPY_AND_ASSIGN(PopupControllerCommon); | 73 DISALLOW_COPY_AND_ASSIGN(PopupControllerCommon); |
| 75 }; | 74 }; |
| 76 | 75 |
| 77 } // namespace autofill | 76 } // namespace autofill |
| 78 | 77 |
| 79 #endif // CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ | 78 #endif // CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_ |
| OLD | NEW |