| 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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Overridden from content::WebContentsDelegate: | 64 // Overridden from content::WebContentsDelegate: |
| 65 virtual content::WebContents* OpenURLFromTab( | 65 virtual content::WebContents* OpenURLFromTab( |
| 66 content::WebContents* source, | 66 content::WebContents* source, |
| 67 const content::OpenURLParams& params) OVERRIDE { | 67 const content::OpenURLParams& params) OVERRIDE { |
| 68 source->GetController().LoadURL( | 68 source->GetController().LoadURL( |
| 69 params.url, params.referrer, params.transition, params.extra_headers); | 69 params.url, params.referrer, params.transition, params.extra_headers); |
| 70 Observe(source); | 70 Observe(source); |
| 71 return source; | 71 return source; |
| 72 } | 72 } |
| 73 | 73 |
| 74 virtual bool IsPopupOrPanel( |
| 75 const content::WebContents* source) const OVERRIDE { |
| 76 return true; |
| 77 } |
| 78 |
| 79 virtual void MoveContents(content::WebContents* source, |
| 80 const gfx::Rect& pos) OVERRIDE { |
| 81 aura::Window* keyboard = proxy_->GetKeyboardWindow(); |
| 82 gfx::Rect bounds = keyboard->bounds(); |
| 83 int new_height = pos.height(); |
| 84 bounds.set_y(bounds.y() + bounds.height() - new_height); |
| 85 bounds.set_height(new_height); |
| 86 proxy_->set_resizing_from_contents(true); |
| 87 keyboard->SetBounds(bounds); |
| 88 proxy_->set_resizing_from_contents(false); |
| 89 } |
| 90 |
| 74 // Overridden from content::WebContentsDelegate: | 91 // Overridden from content::WebContentsDelegate: |
| 75 virtual void RequestMediaAccessPermission(content::WebContents* web_contents, | 92 virtual void RequestMediaAccessPermission(content::WebContents* web_contents, |
| 76 const content::MediaStreamRequest& request, | 93 const content::MediaStreamRequest& request, |
| 77 const content::MediaResponseCallback& callback) OVERRIDE { | 94 const content::MediaResponseCallback& callback) OVERRIDE { |
| 78 proxy_->RequestAudioInput(web_contents, request, callback); | 95 proxy_->RequestAudioInput(web_contents, request, callback); |
| 79 } | 96 } |
| 80 | 97 |
| 81 | 98 |
| 82 // Overridden from content::WebContentsObserver: | 99 // Overridden from content::WebContentsObserver: |
| 83 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE { | 100 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE { |
| 84 delete this; | 101 delete this; |
| 85 } | 102 } |
| 86 | 103 |
| 87 keyboard::KeyboardControllerProxy* proxy_; | 104 keyboard::KeyboardControllerProxy* proxy_; |
| 88 | 105 |
| 89 DISALLOW_COPY_AND_ASSIGN(KeyboardContentsDelegate); | 106 DISALLOW_COPY_AND_ASSIGN(KeyboardContentsDelegate); |
| 90 }; | 107 }; |
| 91 | 108 |
| 92 } // namespace | 109 } // namespace |
| 93 | 110 |
| 94 namespace keyboard { | 111 namespace keyboard { |
| 95 | 112 |
| 96 KeyboardControllerProxy::KeyboardControllerProxy() | 113 KeyboardControllerProxy::KeyboardControllerProxy() |
| 97 : default_url_(kKeyboardWebUIURL) { | 114 : default_url_(kKeyboardWebUIURL), resizing_from_contents_(false) { |
| 98 } | 115 } |
| 99 | 116 |
| 100 KeyboardControllerProxy::~KeyboardControllerProxy() { | 117 KeyboardControllerProxy::~KeyboardControllerProxy() { |
| 101 } | 118 } |
| 102 | 119 |
| 103 const GURL& KeyboardControllerProxy::GetValidUrl() { | 120 const GURL& KeyboardControllerProxy::GetValidUrl() { |
| 104 return override_url_.is_valid() ? override_url_ : default_url_; | 121 return override_url_.is_valid() ? override_url_ : default_url_; |
| 105 } | 122 } |
| 106 | 123 |
| 107 void KeyboardControllerProxy::SetOverrideContentUrl(const GURL& url) { | 124 void KeyboardControllerProxy::SetOverrideContentUrl(const GURL& url) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 132 content::SiteInstance::CreateForURL(context, GetValidUrl())))); | 149 content::SiteInstance::CreateForURL(context, GetValidUrl())))); |
| 133 keyboard_contents_->SetDelegate(new KeyboardContentsDelegate(this)); | 150 keyboard_contents_->SetDelegate(new KeyboardContentsDelegate(this)); |
| 134 SetupWebContents(keyboard_contents_.get()); | 151 SetupWebContents(keyboard_contents_.get()); |
| 135 ReloadContents(); | 152 ReloadContents(); |
| 136 } | 153 } |
| 137 | 154 |
| 138 return keyboard_contents_->GetView()->GetNativeView(); | 155 return keyboard_contents_->GetView()->GetNativeView(); |
| 139 } | 156 } |
| 140 | 157 |
| 141 void KeyboardControllerProxy::ShowKeyboardContainer(aura::Window* container) { | 158 void KeyboardControllerProxy::ShowKeyboardContainer(aura::Window* container) { |
| 159 GetKeyboardWindow()->Show(); |
| 142 container->Show(); | 160 container->Show(); |
| 143 } | 161 } |
| 144 | 162 |
| 145 void KeyboardControllerProxy::HideKeyboardContainer(aura::Window* container) { | 163 void KeyboardControllerProxy::HideKeyboardContainer(aura::Window* container) { |
| 146 container->Hide(); | 164 container->Hide(); |
| 165 GetKeyboardWindow()->Hide(); |
| 147 } | 166 } |
| 148 | 167 |
| 149 void KeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) { | 168 void KeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) { |
| 150 content::WebUI* webui = keyboard_contents_ ? | 169 content::WebUI* webui = keyboard_contents_ ? |
| 151 keyboard_contents_->GetCommittedWebUI() : NULL; | 170 keyboard_contents_->GetCommittedWebUI() : NULL; |
| 152 | 171 |
| 153 if (webui && | 172 if (webui && |
| 154 (0 != (webui->GetBindings() & content::BINDINGS_POLICY_WEB_UI))) { | 173 (0 != (webui->GetBindings() & content::BINDINGS_POLICY_WEB_UI))) { |
| 155 // Only call OnTextInputBoxFocused function if it is a web ui keyboard, | 174 // Only call OnTextInputBoxFocused function if it is a web ui keyboard, |
| 156 // not an extension based keyboard. | 175 // not an extension based keyboard. |
| 157 base::DictionaryValue input_context; | 176 base::DictionaryValue input_context; |
| 158 input_context.SetString("type", TextInputTypeToString(type)); | 177 input_context.SetString("type", TextInputTypeToString(type)); |
| 159 webui->CallJavascriptFunction("OnTextInputBoxFocused", input_context); | 178 webui->CallJavascriptFunction("OnTextInputBoxFocused", input_context); |
| 160 } | 179 } |
| 161 } | 180 } |
| 162 | 181 |
| 163 void KeyboardControllerProxy::SetupWebContents(content::WebContents* contents) { | 182 void KeyboardControllerProxy::SetupWebContents(content::WebContents* contents) { |
| 164 } | 183 } |
| 165 | 184 |
| 166 } // namespace keyboard | 185 } // namespace keyboard |
| OLD | NEW |