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 #include "chrome/browser/ui/autofill/popup_controller_common.h" | 5 #include "chrome/browser/ui/autofill/popup_controller_common.h" |
6 | 6 |
7 #include "content/public/browser/render_view_host.h" | |
8 #include "content/public/browser/web_contents.h" | |
9 | |
10 namespace autofill { | 7 namespace autofill { |
11 | 8 |
12 PopupControllerCommon::PopupControllerCommon( | 9 PopupControllerCommon::PopupControllerCommon( |
13 const gfx::RectF& element_bounds, | 10 const gfx::RectF& element_bounds, |
14 base::i18n::TextDirection text_direction, | 11 base::i18n::TextDirection text_direction, |
15 const gfx::NativeView container_view, | 12 gfx::NativeView container_view) |
16 content::WebContents* web_contents) | 13 : element_bounds(element_bounds), |
17 : element_bounds_(element_bounds), | 14 text_direction(text_direction), |
18 text_direction_(text_direction), | 15 container_view(container_view) {} |
19 container_view_(container_view), | 16 |
20 web_contents_(web_contents), | |
21 key_press_event_target_(NULL) { | |
22 } | |
23 PopupControllerCommon::~PopupControllerCommon() {} | 17 PopupControllerCommon::~PopupControllerCommon() {} |
24 | 18 |
25 void PopupControllerCommon::SetKeyPressCallback( | |
26 content::RenderWidgetHost::KeyPressEventCallback callback) { | |
27 DCHECK(key_press_event_callback_.is_null()); | |
28 key_press_event_callback_ = callback; | |
29 } | |
30 | |
31 void PopupControllerCommon::RegisterKeyPressCallback() { | |
32 if (web_contents_ && !key_press_event_target_) { | |
33 key_press_event_target_ = web_contents_->GetRenderViewHost(); | |
34 key_press_event_target_->GetWidget()->AddKeyPressEventCallback( | |
35 key_press_event_callback_); | |
36 } | |
37 } | |
38 | |
39 void PopupControllerCommon::RemoveKeyPressCallback() { | |
40 if (web_contents_ && (!web_contents_->IsBeingDestroyed()) && | |
41 key_press_event_target_ == web_contents_->GetRenderViewHost()) { | |
42 web_contents_->GetRenderViewHost() | |
43 ->GetWidget() | |
44 ->RemoveKeyPressEventCallback(key_press_event_callback_); | |
45 } | |
46 key_press_event_target_ = NULL; | |
47 } | |
48 | |
49 } // namespace autofill | 19 } // namespace autofill |
OLD | NEW |