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

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

Issue 10170014: Move text input API to Instance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/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
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // process. The failure also happens if we output nothing here. 144 // process. The failure also happens if we output nothing here.
145 // We need to investigate the reason for this failure and fix it. 145 // We need to investigate the reason for this failure and fix it.
146 // In the meantime this temporary hack of drawing an empty 146 // In the meantime this temporary hack of drawing an empty
147 // rectangle in the DC gets us by. 147 // rectangle in the DC gets us by.
148 Rectangle(dc, 0, 0, 0, 0); 148 Rectangle(dc, 0, 0, 0, 0);
149 } 149 }
150 #endif // defined(OS_WIN) 150 #endif // defined(OS_WIN)
151 151
152 namespace { 152 namespace {
153 153
154 // Check PP_TextInput_Type and ui::TextInputType are kept in sync.
155 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == \
156 int(PP_TEXTINPUT_TYPE_NONE), mismatching_enums);
157 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == \
158 int(PP_TEXTINPUT_TYPE_TEXT), mismatching_enums);
159 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) == \
160 int(PP_TEXTINPUT_TYPE_PASSWORD), mismatching_enums);
161 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_SEARCH) == \
162 int(PP_TEXTINPUT_TYPE_SEARCH), mismatching_enums);
163 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_EMAIL) == \
164 int(PP_TEXTINPUT_TYPE_EMAIL), mismatching_enums);
165 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NUMBER) == \
166 int(PP_TEXTINPUT_TYPE_NUMBER), mismatching_enums);
167 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TELEPHONE) == \
168 int(PP_TEXTINPUT_TYPE_TELEPHONE), mismatching_enums);
169 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_URL) == \
170 int(PP_TEXTINPUT_TYPE_URL), mismatching_enums);
171
154 // The default text input type is to regard the plugin always accept text input. 172 // The default text input type is to regard the plugin always accept text input.
155 // This is for allowing users to use input methods even on completely-IME- 173 // This is for allowing users to use input methods even on completely-IME-
156 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). 174 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16).
157 // Plugins need to explicitly opt out the text input mode if they know 175 // Plugins need to explicitly opt out the text input mode if they know
158 // that they don't accept texts. 176 // that they don't accept texts.
159 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; 177 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT;
160 178
161 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ 179 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \
162 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ 180 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \
163 == static_cast<int>(np_name), \ 181 == static_cast<int>(np_name), \
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 bool PluginInstance::HandleCompositionEnd(const string16& text) { 602 bool PluginInstance::HandleCompositionEnd(const string16& text) {
585 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_END, 603 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_END,
586 text); 604 text);
587 } 605 }
588 606
589 bool PluginInstance::HandleTextInput(const string16& text) { 607 bool PluginInstance::HandleTextInput(const string16& text) {
590 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT, 608 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT,
591 text); 609 text);
592 } 610 }
593 611
594 void PluginInstance::UpdateCaretPosition(const gfx::Rect& caret,
595 const gfx::Rect& bounding_box) {
596 text_input_caret_ = caret;
597 text_input_caret_bounds_ = bounding_box;
598 text_input_caret_set_ = true;
599 delegate()->PluginCaretPositionChanged(this);
600 }
601
602 void PluginInstance::SetTextInputType(ui::TextInputType type) {
603 text_input_type_ = type;
604 delegate()->PluginTextInputTypeChanged(this);
605 }
606
607 void PluginInstance::SelectionChanged() {
608 // TODO(kinaba): currently the browser always calls RequestSurroundingText.
609 // It can be optimized so that it won't call it back until the information
610 // is really needed.
611
612 // Avoid calling in nested context or else this will reenter the plugin. This
613 // uses a weak pointer rather than exploiting the fact that this class is
614 // refcounted because we don't actually want this operation to affect the
615 // lifetime of the instance.
616 MessageLoop::current()->PostTask(FROM_HERE,
617 base::Bind(&PluginInstance::RequestSurroundingText,
618 AsWeakPtr(),
619 static_cast<size_t>(kExtraCharsForTextInput)));
620 }
621
622 void PluginInstance::UpdateSurroundingText(const std::string& text,
623 size_t caret, size_t anchor) {
624 surrounding_text_ = text;
625 selection_caret_ = caret;
626 selection_anchor_ = anchor;
627 delegate()->PluginSelectionChanged(this);
628 }
629
630 void PluginInstance::GetSurroundingText(string16* text, 612 void PluginInstance::GetSurroundingText(string16* text,
631 ui::Range* range) const { 613 ui::Range* range) const {
632 std::vector<size_t> offsets; 614 std::vector<size_t> offsets;
633 offsets.push_back(selection_anchor_); 615 offsets.push_back(selection_anchor_);
634 offsets.push_back(selection_caret_); 616 offsets.push_back(selection_caret_);
635 *text = UTF8ToUTF16AndAdjustOffsets(surrounding_text_, &offsets); 617 *text = UTF8ToUTF16AndAdjustOffsets(surrounding_text_, &offsets);
636 range->set_start(offsets[0] == string16::npos ? text->size() : offsets[0]); 618 range->set_start(offsets[0] == string16::npos ? text->size() : offsets[0]);
637 range->set_end(offsets[1] == string16::npos ? text->size() : offsets[1]); 619 range->set_end(offsets[1] == string16::npos ? text->size() : offsets[1]);
638 } 620 }
639 621
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 return PP_OK_COMPLETIONPENDING; 1887 return PP_OK_COMPLETIONPENDING;
1906 } else { 1888 } else {
1907 return PP_ERROR_FAILED; 1889 return PP_ERROR_FAILED;
1908 } 1890 }
1909 } 1891 }
1910 1892
1911 void PluginInstance::UnlockMouse(PP_Instance instance) { 1893 void PluginInstance::UnlockMouse(PP_Instance instance) {
1912 delegate()->UnlockMouse(this); 1894 delegate()->UnlockMouse(this);
1913 } 1895 }
1914 1896
1897 void PluginInstance::SetTextInputType(PP_Instance instance,
1898 PP_TextInput_Type type) {
1899 int itype = type;
1900 if (itype < 0 || itype > ui::TEXT_INPUT_TYPE_URL)
1901 itype = ui::TEXT_INPUT_TYPE_NONE;
1902 text_input_type_ = static_cast<ui::TextInputType>(itype);
1903 delegate()->PluginTextInputTypeChanged(this);
1904 }
1905
1906 void PluginInstance::UpdateCaretPosition(PP_Instance instance,
1907 const PP_Rect& caret,
1908 const PP_Rect& bounding_box) {
1909 text_input_caret_ = PP_ToGfxRect(caret);
1910 text_input_caret_bounds_ = PP_ToGfxRect(bounding_box);
1911 text_input_caret_set_ = true;
1912 delegate()->PluginCaretPositionChanged(this);
1913 }
1914
1915 void PluginInstance::CancelCompositionText(PP_Instance instance) {
1916 delegate()->PluginRequestedCancelComposition(this);
1917 }
1918
1919 void PluginInstance::SelectionChanged(PP_Instance instance) {
1920 // TODO(kinaba): currently the browser always calls RequestSurroundingText.
1921 // It can be optimized so that it won't call it back until the information
1922 // is really needed.
1923
1924 // Avoid calling in nested context or else this will reenter the plugin. This
1925 // uses a weak pointer rather than exploiting the fact that this class is
1926 // refcounted because we don't actually want this operation to affect the
1927 // lifetime of the instance.
1928 MessageLoop::current()->PostTask(FROM_HERE,
1929 base::Bind(&PluginInstance::RequestSurroundingText,
1930 AsWeakPtr(),
1931 static_cast<size_t>(kExtraCharsForTextInput)));
1932 }
1933
1934 void PluginInstance::UpdateSurroundingText(PP_Instance instance,
1935 const char* text,
1936 uint32_t caret,
1937 uint32_t anchor) {
1938 surrounding_text_ = text;
1939 selection_caret_ = caret;
1940 selection_anchor_ = anchor;
1941 delegate()->PluginSelectionChanged(this);
1942 }
1943
1915 PP_Var PluginInstance::ResolveRelativeToDocument( 1944 PP_Var PluginInstance::ResolveRelativeToDocument(
1916 PP_Instance instance, 1945 PP_Instance instance,
1917 PP_Var relative, 1946 PP_Var relative,
1918 PP_URLComponents_Dev* components) { 1947 PP_URLComponents_Dev* components) {
1919 StringVar* relative_string = StringVar::FromPPVar(relative); 1948 StringVar* relative_string = StringVar::FromPPVar(relative);
1920 if (!relative_string) 1949 if (!relative_string)
1921 return PP_MakeNull(); 1950 return PP_MakeNull();
1922 1951
1923 WebElement plugin_element = container()->element(); 1952 WebElement plugin_element = container()->element();
1924 GURL document_url = plugin_element.document().baseURL(); 1953 GURL document_url = plugin_element.document().baseURL();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 screen_size_for_fullscreen_ = gfx::Size(); 2062 screen_size_for_fullscreen_ = gfx::Size();
2034 WebElement element = container_->element(); 2063 WebElement element = container_->element();
2035 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2064 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2036 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2065 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2037 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2066 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2038 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2067 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2039 } 2068 }
2040 2069
2041 } // namespace ppapi 2070 } // namespace ppapi
2042 } // namespace webkit 2071 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698