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

Side by Side Diff: webkit/glue/webtextinput_impl.cc

Issue 164225: Switch to WebFrame from the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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/glue/webtextinput_impl.h ('k') | webkit/glue/webview.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 <ctype.h>
6 #include "config.h"
7
8 #include "base/compiler_specific.h"
9
10 MSVC_PUSH_WARNING_LEVEL(0);
11 #include "Frame.h"
12 #include "Editor.h"
13 MSVC_POP_WARNING();
14
15 #undef LOG
16
17 #include "base/string16.h"
18 #include "base/string_util.h"
19 #include "webkit/glue/glue_util.h"
20 #include "webkit/glue/webframe_impl.h"
21 #include "webkit/glue/webtextinput_impl.h"
22
23 WebTextInputImpl::WebTextInputImpl(WebFrameImpl* web_frame_impl)
24 : WebTextInput(),
25 web_frame_impl_(web_frame_impl) {
26 }
27
28 WebTextInputImpl::~WebTextInputImpl() {
29 }
30
31 WebCore::Frame* WebTextInputImpl::GetFrame() {
32 return web_frame_impl_->frame();
33 }
34
35 WebCore::Editor* WebTextInputImpl::GetEditor() {
36 return web_frame_impl_->frame()->editor();
37 }
38
39 void WebTextInputImpl::InsertText(const string16& text) {
40 WebCore::String str = webkit_glue::String16ToString(text);
41 GetEditor()->insertText(str, NULL);
42 }
43
44 void WebTextInputImpl::DoCommand(const string16& com) {
45 if (com.length() <= 2)
46 return;
47
48 // Since we don't have NSControl, we will convert the format of command
49 // string and call the function on Editor directly.
50 string16 command = com;
51
52 // Make sure the first letter is upper case.
53 command.replace(0, 1, 1, toupper(command.at(0)));
54
55 // Remove the trailing ':' if existing.
56 if (command.at(command.length() - 1) == ':')
57 command.erase(command.length() - 1, 1);
58
59 // Specially handling commands that Editor::execCommand does not directly
60 // support.
61 if (EqualsASCII(command, "DeleteToEndOfParagraph")) {
62 DeleteToEndOfParagraph();
63 } else if(EqualsASCII(command, "Indent")) {
64 GetEditor()->indent();
65 } else if(EqualsASCII(command, "Outdent")) {
66 GetEditor()->outdent();
67 } else if(EqualsASCII(command, "DeleteBackward")) {
68 WebCore::AtomicString editor_command("BackwardDelete");
69 GetEditor()->command(editor_command).execute();
70 } else if(EqualsASCII(command, "DeleteForward")) {
71 WebCore::AtomicString editor_command("ForwardDelete");
72 GetEditor()->command(editor_command).execute();
73 } else {
74 WebCore::AtomicString editor_command(command.c_str());
75 GetEditor()->command(editor_command).execute();
76 }
77
78 return;
79 }
80
81 void WebTextInputImpl::SetMarkedText(const string16& text,
82 int32_t location,
83 int32_t length) {
84 WebCore::Editor* editor = GetEditor();
85 WebCore::String str = webkit_glue::String16ToString(text);
86
87 editor->confirmComposition(str);
88
89 WTF::Vector<WebCore::CompositionUnderline> decorations;
90
91 editor->setComposition(str, decorations, location, length);
92 }
93
94 void WebTextInputImpl::UnMarkText() {
95 GetEditor()->confirmCompositionWithoutDisturbingSelection();;
96 }
97
98 bool WebTextInputImpl::HasMarkedText() {
99 return GetEditor()->hasComposition();
100 }
101
102 void WebTextInputImpl::ConversationIdentifier() {
103 }
104
105 void WebTextInputImpl::SubstringFromRange(int32_t location, int32_t length) {
106 }
107
108 void WebTextInputImpl::AttributedSubstringFromRange(int32_t location,
109 int32_t length) {
110 }
111
112 void WebTextInputImpl::MarkedRange(std::string* range_str) {
113 RefPtr<WebCore::Range> range = GetEditor()->compositionRange();
114
115 // Range::toString() returns a string different from what test expects.
116 // So we need to construct the string ourselves.
117 SStringPrintf(range_str, "%d,%d", range->startPosition().deprecatedEditingOffs et(),
118 range->endPosition().deprecatedEditingOffset());
119 }
120
121 void WebTextInputImpl::SelectedRange(std::string* range_str) {
122 WTF::RefPtr<WebCore::Range> range
123 = GetFrame()->selection()->toNormalizedRange();
124
125 // Range::toString() returns a string different from what test expects.
126 // So we need to construct the string ourselves.
127 SStringPrintf(range_str, "%d,%d", range.get()->startPosition().deprecatedEditi ngOffset(),
128 range.get()->endPosition().deprecatedEditingOffset());
129 }
130
131 void WebTextInputImpl::FirstRectForCharacterRange(int32_t location,
132 int32_t length) {
133 }
134
135 void WebTextInputImpl::CharacterIndexForPoint(double x, double y) {
136 }
137
138 void WebTextInputImpl::ValidAttributesForMarkedText(std::string* attributes) {
139 // We simply return a string with relevant keywords.
140 attributes->assign("NSUnderline,NSUnderlineColor,NSMarkedClauseSegment,NSTextI nputReplacementRangeAttributeName");
141 }
142
143 void WebTextInputImpl::MakeAttributedString(const std::string& str) {
144 }
145
146 void WebTextInputImpl::DeleteToEndOfParagraph() {
147 WebCore::Editor* editor = GetEditor();
148 if (!editor->deleteWithDirection(WebCore::SelectionController::FORWARD,
149 WebCore::ParagraphBoundary,
150 true,
151 false)) {
152 editor->deleteWithDirection(WebCore::SelectionController::FORWARD,
153 WebCore::CharacterGranularity,
154 true,
155 false);
156 }
157 }
OLDNEW
« no previous file with comments | « webkit/glue/webtextinput_impl.h ('k') | webkit/glue/webview.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698