Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1614)

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 10083013: Merge 132027 - Make the text input not require round-trips when the text is updated. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1084/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 643
649 void PluginInstance::SetTextInputType(ui::TextInputType type) { 644 void PluginInstance::SetTextInputType(ui::TextInputType type) {
650 text_input_type_ = type; 645 text_input_type_ = type;
651 delegate()->PluginTextInputTypeChanged(this); 646 delegate()->PluginTextInputTypeChanged(this);
652 } 647 }
653 648
654 void PluginInstance::SelectionChanged() { 649 void PluginInstance::SelectionChanged() {
655 // TODO(kinaba): currently the browser always calls RequestSurroundingText. 650 // TODO(kinaba): currently the browser always calls RequestSurroundingText.
656 // It can be optimized so that it won't call it back until the information 651 // It can be optimized so that it won't call it back until the information
657 // is really needed. 652 // is really needed.
658 RequestSurroundingText(kExtraCharsBeforeAndAfterSelection); 653
654 // Avoid calling in nested context or else this will reenter the plugin. This
655 // uses a weak pointer rather than exploiting the fact that this class is
656 // refcounted because we don't actually want this operation to affect the
657 // lifetime of the instance.
658 MessageLoop::current()->PostTask(FROM_HERE,
659 base::Bind(&PluginInstance::RequestSurroundingText,
660 AsWeakPtr(),
661 static_cast<size_t>(kExtraCharsForTextInput)));
659 } 662 }
660 663
661 void PluginInstance::UpdateSurroundingText(const std::string& text, 664 void PluginInstance::UpdateSurroundingText(const std::string& text,
662 size_t caret, size_t anchor) { 665 size_t caret, size_t anchor) {
663 surrounding_text_ = text; 666 surrounding_text_ = text;
664 selection_caret_ = caret; 667 selection_caret_ = caret;
665 selection_anchor_ = anchor; 668 selection_anchor_ = anchor;
666 delegate()->PluginSelectionChanged(this); 669 delegate()->PluginSelectionChanged(this);
667 } 670 }
668 671
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); 940 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p);
938 StringVar* string = StringVar::FromPPVar(rv); 941 StringVar* string = StringVar::FromPPVar(rv);
939 string16 link; 942 string16 link;
940 if (string) 943 if (string)
941 link = UTF8ToUTF16(string->value()); 944 link = UTF8ToUTF16(string->value());
942 // Release the ref the plugin transfered to us. 945 // Release the ref the plugin transfered to us.
943 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); 946 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv);
944 return link; 947 return link;
945 } 948 }
946 949
947 bool PluginInstance::RequestSurroundingText( 950 void PluginInstance::RequestSurroundingText(
948 size_t desired_number_of_characters) { 951 size_t desired_number_of_characters) {
949 // Keep a reference on the stack. See NOTE above. 952 // Keep a reference on the stack. See NOTE above.
950 scoped_refptr<PluginInstance> ref(this); 953 scoped_refptr<PluginInstance> ref(this);
951 if (!LoadTextInputInterface()) 954 if (!LoadTextInputInterface())
952 return false; 955 return;
953 plugin_textinput_interface_->RequestSurroundingText( 956 plugin_textinput_interface_->RequestSurroundingText(
954 pp_instance(), desired_number_of_characters); 957 pp_instance(), desired_number_of_characters);
955 return true;
956 } 958 }
957 959
958 void PluginInstance::Zoom(double factor, bool text_only) { 960 void PluginInstance::Zoom(double factor, bool text_only) {
959 // Keep a reference on the stack. See NOTE above. 961 // Keep a reference on the stack. See NOTE above.
960 scoped_refptr<PluginInstance> ref(this); 962 scoped_refptr<PluginInstance> ref(this);
961 if (!LoadZoomInterface()) 963 if (!LoadZoomInterface())
962 return; 964 return;
963 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); 965 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only));
964 } 966 }
965 967
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 screen_size_for_fullscreen_ = gfx::Size(); 2170 screen_size_for_fullscreen_ = gfx::Size();
2169 WebElement element = container_->element(); 2171 WebElement element = container_->element();
2170 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2172 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2171 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2173 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2172 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2174 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2173 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2175 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2174 } 2176 }
2175 2177
2176 } // namespace ppapi 2178 } // namespace ppapi
2177 } // namespace webkit 2179 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698