OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/keyboard/keyboard_controller_proxy.h" | 5 #include "ui/keyboard/keyboard_controller_proxy.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "content/public/browser/site_instance.h" | 8 #include "content/public/browser/site_instance.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
11 #include "content/public/browser/web_contents_delegate.h" | 11 #include "content/public/browser/web_contents_delegate.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
14 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
15 #include "content/public/common/bindings_policy.h" | 15 #include "content/public/common/bindings_policy.h" |
16 #include "ui/aura/layout_manager.h" | 16 #include "ui/aura/layout_manager.h" |
17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #include "ui/keyboard/keyboard_constants.h" | 18 #include "ui/keyboard/keyboard_constants.h" |
19 #include "ui/keyboard/keyboard_util.h" | 19 #include "ui/keyboard/keyboard_util.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Converts ui::TextInputType to string. | |
24 std::string TextInputTypeToString(ui::TextInputType type) { | |
25 switch (type) { | |
26 case ui::TEXT_INPUT_TYPE_NONE: | |
27 return "none"; | |
28 case ui::TEXT_INPUT_TYPE_PASSWORD: | |
29 return "password"; | |
30 case ui::TEXT_INPUT_TYPE_EMAIL: | |
31 return "email"; | |
32 case ui::TEXT_INPUT_TYPE_NUMBER: | |
33 return "number"; | |
34 case ui::TEXT_INPUT_TYPE_TELEPHONE: | |
35 return "tel"; | |
36 case ui::TEXT_INPUT_TYPE_URL: | |
37 return "url"; | |
38 case ui::TEXT_INPUT_TYPE_DATE: | |
39 return "date"; | |
40 case ui::TEXT_INPUT_TYPE_TEXT: | |
41 case ui::TEXT_INPUT_TYPE_SEARCH: | |
42 case ui::TEXT_INPUT_TYPE_DATE_TIME: | |
43 case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: | |
44 case ui::TEXT_INPUT_TYPE_MONTH: | |
45 case ui::TEXT_INPUT_TYPE_TIME: | |
46 case ui::TEXT_INPUT_TYPE_WEEK: | |
47 case ui::TEXT_INPUT_TYPE_TEXT_AREA: | |
48 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE: | |
49 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: | |
50 return "text"; | |
51 } | |
52 NOTREACHED(); | |
53 return ""; | |
54 } | |
55 | |
56 // The WebContentsDelegate for the keyboard. | 23 // The WebContentsDelegate for the keyboard. |
57 // The delegate deletes itself when the keyboard is destroyed. | 24 // The delegate deletes itself when the keyboard is destroyed. |
58 class KeyboardContentsDelegate : public content::WebContentsDelegate, | 25 class KeyboardContentsDelegate : public content::WebContentsDelegate, |
59 public content::WebContentsObserver { | 26 public content::WebContentsObserver { |
60 public: | 27 public: |
61 KeyboardContentsDelegate(keyboard::KeyboardControllerProxy* proxy) | 28 KeyboardContentsDelegate(keyboard::KeyboardControllerProxy* proxy) |
62 : proxy_(proxy) {} | 29 : proxy_(proxy) {} |
63 virtual ~KeyboardContentsDelegate() {} | 30 virtual ~KeyboardContentsDelegate() {} |
64 | 31 |
65 private: | 32 private: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 keyboard::KeyboardControllerProxy* proxy_; | 72 keyboard::KeyboardControllerProxy* proxy_; |
106 | 73 |
107 DISALLOW_COPY_AND_ASSIGN(KeyboardContentsDelegate); | 74 DISALLOW_COPY_AND_ASSIGN(KeyboardContentsDelegate); |
108 }; | 75 }; |
109 | 76 |
110 } // namespace | 77 } // namespace |
111 | 78 |
112 namespace keyboard { | 79 namespace keyboard { |
113 | 80 |
114 KeyboardControllerProxy::KeyboardControllerProxy() | 81 KeyboardControllerProxy::KeyboardControllerProxy() |
115 : default_url_(kKeyboardWebUIURL), resizing_from_contents_(false) { | 82 : default_url_(kKeyboardURL), resizing_from_contents_(false) { |
116 } | 83 } |
117 | 84 |
118 KeyboardControllerProxy::~KeyboardControllerProxy() { | 85 KeyboardControllerProxy::~KeyboardControllerProxy() { |
119 } | 86 } |
120 | 87 |
121 const GURL& KeyboardControllerProxy::GetVirtualKeyboardUrl() { | 88 const GURL& KeyboardControllerProxy::GetVirtualKeyboardUrl() { |
122 const GURL& override_url = GetOverrideContentUrl(); | 89 const GURL& override_url = GetOverrideContentUrl(); |
123 return override_url.is_valid() ? override_url : default_url_; | 90 return override_url.is_valid() ? override_url : default_url_; |
124 } | 91 } |
125 | 92 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 GetKeyboardWindow()->Show(); | 125 GetKeyboardWindow()->Show(); |
159 container->Show(); | 126 container->Show(); |
160 } | 127 } |
161 | 128 |
162 void KeyboardControllerProxy::HideKeyboardContainer(aura::Window* container) { | 129 void KeyboardControllerProxy::HideKeyboardContainer(aura::Window* container) { |
163 container->Hide(); | 130 container->Hide(); |
164 GetKeyboardWindow()->Hide(); | 131 GetKeyboardWindow()->Hide(); |
165 } | 132 } |
166 | 133 |
167 void KeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) { | 134 void KeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) { |
168 content::WebUI* webui = keyboard_contents_ ? | |
169 keyboard_contents_->GetCommittedWebUI() : NULL; | |
170 | |
171 if (webui && | |
172 (0 != (webui->GetBindings() & content::BINDINGS_POLICY_WEB_UI))) { | |
173 // Only call OnTextInputBoxFocused function if it is a web ui keyboard, | |
174 // not an extension based keyboard. | |
175 base::DictionaryValue input_context; | |
176 input_context.SetString("type", TextInputTypeToString(type)); | |
177 webui->CallJavascriptFunction("OnTextInputBoxFocused", input_context); | |
178 } | |
179 } | 135 } |
180 | 136 |
181 void KeyboardControllerProxy::EnsureCaretInWorkArea() { | 137 void KeyboardControllerProxy::EnsureCaretInWorkArea() { |
182 } | 138 } |
183 | 139 |
184 void KeyboardControllerProxy::LoadSystemKeyboard() { | 140 void KeyboardControllerProxy::LoadSystemKeyboard() { |
185 DCHECK(keyboard_contents_); | 141 DCHECK(keyboard_contents_); |
186 if (keyboard_contents_->GetURL() != default_url_) { | 142 if (keyboard_contents_->GetURL() != default_url_) { |
187 // TODO(bshe): The height of system virtual keyboard and IME virtual | 143 // TODO(bshe): The height of system virtual keyboard and IME virtual |
188 // keyboard may different. The height needs to be restored too. | 144 // keyboard may different. The height needs to be restored too. |
189 LoadContents(default_url_); | 145 LoadContents(default_url_); |
190 } | 146 } |
191 } | 147 } |
192 | 148 |
193 void KeyboardControllerProxy::ReloadKeyboardIfNeeded() { | 149 void KeyboardControllerProxy::ReloadKeyboardIfNeeded() { |
194 DCHECK(keyboard_contents_); | 150 DCHECK(keyboard_contents_); |
195 if (keyboard_contents_->GetURL() != GetVirtualKeyboardUrl()) { | 151 if (keyboard_contents_->GetURL() != GetVirtualKeyboardUrl()) { |
196 LoadContents(GetVirtualKeyboardUrl()); | 152 LoadContents(GetVirtualKeyboardUrl()); |
197 } | 153 } |
198 } | 154 } |
199 | 155 |
200 void KeyboardControllerProxy::SetupWebContents(content::WebContents* contents) { | 156 void KeyboardControllerProxy::SetupWebContents(content::WebContents* contents) { |
201 } | 157 } |
202 | 158 |
203 } // namespace keyboard | 159 } // namespace keyboard |
OLD | NEW |