| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 namespace { | 151 namespace { |
| 152 | 152 |
| 153 // The default text input type is to regard the plugin always accept text input. | 153 // The default text input type is to regard the plugin always accept text input. |
| 154 // This is for allowing users to use input methods even on completely-IME- | 154 // This is for allowing users to use input methods even on completely-IME- |
| 155 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). | 155 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). |
| 156 // Plugins need to explicitly opt out the text input mode if they know | 156 // Plugins need to explicitly opt out the text input mode if they know |
| 157 // that they don't accept texts. | 157 // that they don't accept texts. |
| 158 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; | 158 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; |
| 159 | 159 |
| 160 // The length of text to request as a surrounding context of selection. | |
| 161 // For now, the value is copied from the one with render_view_impl.cc. | |
| 162 // TODO(kinaba) implement a way to dynamically sync the requirement. | |
| 163 static const size_t kExtraCharsBeforeAndAfterSelection = 100; | |
| 164 | |
| 165 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ | 160 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ |
| 166 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ | 161 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ |
| 167 == static_cast<int>(np_name), \ | 162 == static_cast<int>(np_name), \ |
| 168 mismatching_enums) | 163 mismatching_enums) |
| 169 | 164 |
| 170 // <embed>/<object> attributes. | 165 // <embed>/<object> attributes. |
| 171 const char kWidth[] = "width"; | 166 const char kWidth[] = "width"; |
| 172 const char kHeight[] = "height"; | 167 const char kHeight[] = "height"; |
| 173 const char kBorder[] = "border"; // According to w3c, deprecated. | 168 const char kBorder[] = "border"; // According to w3c, deprecated. |
| 174 const char kStyle[] = "style"; | 169 const char kStyle[] = "style"; |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 598 |
| 604 void PluginInstance::SetTextInputType(ui::TextInputType type) { | 599 void PluginInstance::SetTextInputType(ui::TextInputType type) { |
| 605 text_input_type_ = type; | 600 text_input_type_ = type; |
| 606 delegate()->PluginTextInputTypeChanged(this); | 601 delegate()->PluginTextInputTypeChanged(this); |
| 607 } | 602 } |
| 608 | 603 |
| 609 void PluginInstance::SelectionChanged() { | 604 void PluginInstance::SelectionChanged() { |
| 610 // TODO(kinaba): currently the browser always calls RequestSurroundingText. | 605 // TODO(kinaba): currently the browser always calls RequestSurroundingText. |
| 611 // It can be optimized so that it won't call it back until the information | 606 // It can be optimized so that it won't call it back until the information |
| 612 // is really needed. | 607 // is really needed. |
| 613 RequestSurroundingText(kExtraCharsBeforeAndAfterSelection); | 608 |
| 609 // Avoid calling in nested context or else this will reenter the plugin. This |
| 610 // uses a weak pointer rather than exploiting the fact that this class is |
| 611 // refcounted because we don't actually want this operation to affect the |
| 612 // lifetime of the instance. |
| 613 MessageLoop::current()->PostTask(FROM_HERE, |
| 614 base::Bind(&PluginInstance::RequestSurroundingText, |
| 615 AsWeakPtr(), |
| 616 static_cast<size_t>(kExtraCharsForTextInput))); |
| 614 } | 617 } |
| 615 | 618 |
| 616 void PluginInstance::UpdateSurroundingText(const std::string& text, | 619 void PluginInstance::UpdateSurroundingText(const std::string& text, |
| 617 size_t caret, size_t anchor) { | 620 size_t caret, size_t anchor) { |
| 618 surrounding_text_ = text; | 621 surrounding_text_ = text; |
| 619 selection_caret_ = caret; | 622 selection_caret_ = caret; |
| 620 selection_anchor_ = anchor; | 623 selection_anchor_ = anchor; |
| 621 delegate()->PluginSelectionChanged(this); | 624 delegate()->PluginSelectionChanged(this); |
| 622 } | 625 } |
| 623 | 626 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); | 895 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); |
| 893 StringVar* string = StringVar::FromPPVar(rv); | 896 StringVar* string = StringVar::FromPPVar(rv); |
| 894 string16 link; | 897 string16 link; |
| 895 if (string) | 898 if (string) |
| 896 link = UTF8ToUTF16(string->value()); | 899 link = UTF8ToUTF16(string->value()); |
| 897 // Release the ref the plugin transfered to us. | 900 // Release the ref the plugin transfered to us. |
| 898 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); | 901 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); |
| 899 return link; | 902 return link; |
| 900 } | 903 } |
| 901 | 904 |
| 902 bool PluginInstance::RequestSurroundingText( | 905 void PluginInstance::RequestSurroundingText( |
| 903 size_t desired_number_of_characters) { | 906 size_t desired_number_of_characters) { |
| 904 // Keep a reference on the stack. See NOTE above. | 907 // Keep a reference on the stack. See NOTE above. |
| 905 scoped_refptr<PluginInstance> ref(this); | 908 scoped_refptr<PluginInstance> ref(this); |
| 906 if (!LoadTextInputInterface()) | 909 if (!LoadTextInputInterface()) |
| 907 return false; | 910 return; |
| 908 plugin_textinput_interface_->RequestSurroundingText( | 911 plugin_textinput_interface_->RequestSurroundingText( |
| 909 pp_instance(), desired_number_of_characters); | 912 pp_instance(), desired_number_of_characters); |
| 910 return true; | |
| 911 } | 913 } |
| 912 | 914 |
| 913 void PluginInstance::Zoom(double factor, bool text_only) { | 915 void PluginInstance::Zoom(double factor, bool text_only) { |
| 914 // Keep a reference on the stack. See NOTE above. | 916 // Keep a reference on the stack. See NOTE above. |
| 915 scoped_refptr<PluginInstance> ref(this); | 917 scoped_refptr<PluginInstance> ref(this); |
| 916 if (!LoadZoomInterface()) | 918 if (!LoadZoomInterface()) |
| 917 return; | 919 return; |
| 918 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); | 920 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); |
| 919 } | 921 } |
| 920 | 922 |
| (...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2172 screen_size_for_fullscreen_ = gfx::Size(); | 2174 screen_size_for_fullscreen_ = gfx::Size(); |
| 2173 WebElement element = container_->element(); | 2175 WebElement element = container_->element(); |
| 2174 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2176 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2175 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2177 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2176 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2178 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2177 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2179 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2178 } | 2180 } |
| 2179 | 2181 |
| 2180 } // namespace ppapi | 2182 } // namespace ppapi |
| 2181 } // namespace webkit | 2183 } // namespace webkit |
| OLD | NEW |