1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/views/textfield_views.h" 6 7 #include "base/utf_string_conversions.h" 8 #include "base/values.h" 9 #include "chrome/browser/ui/webui/textfields_ui.h" 10 #include "content/browser/tab_contents/tab_contents.h" 11 12 TextfieldViews::TextfieldViews() : DOMView() {} 13 14 std::wstring TextfieldViews::GetText() { 15 TextfieldsUI* textfields_ui = web_ui(); 16 return (textfields_ui) ? textfields_ui->text() : std::wstring(); 17 } 18 19 void TextfieldViews::SetText(const std::wstring& text) { 20 TextfieldsUI* textfields_ui = web_ui(); 21 if (textfields_ui) { 22 StringValue text_value(WideToUTF16(text)); 23 textfields_ui->CallJavascriptFunction("setTextfieldValue", text_value); 24 } 25 SchedulePaint(); 26 } 27 28 TextfieldsUI* TextfieldViews::web_ui() { 29 TextfieldsUI* web_ui = NULL; 30 if (tab_contents_.get() && tab_contents_->web_ui()) { 31 web_ui = static_cast<TextfieldsUI*>(tab_contents_->web_ui()); 32 } 33 return web_ui; 34 } 35