1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <ctype.h>
#include "config.h"
#pragma warning(push, 0)
#include "Frame.h"
#include "Editor.h"
#pragma warning(pop)
#undef LOG
#include "base/string_util.h"
#include "webkit/glue/webframe_impl.h"
#include "webkit/glue/webtextinput_impl.h"
WebTextInputImpl::WebTextInputImpl(WebFrameImpl* web_frame_impl)
: WebTextInput(),
web_frame_impl_(web_frame_impl) {
}
WebTextInputImpl::~WebTextInputImpl() {
}
WebCore::Frame* WebTextInputImpl::GetFrame() {
return web_frame_impl_->frame();
}
WebCore::Editor* WebTextInputImpl::GetEditor() {
return web_frame_impl_->frame()->editor();
}
void WebTextInputImpl::InsertText(const std::string& text) {
WebCore::String str(text.c_str());
GetEditor()->insertText(str, NULL);
}
void WebTextInputImpl::DoCommand(const std::string& com) {
if (com.length() <= 2)
return;
// Since we don't have NSControl, we will convert the format of command
// string and call the function on Editor directly.
std::string command = com;
// Make sure the first letter is upper case.
command.replace(0, 1, 1, toupper(command.at(0)));
// Remove the trailing ':' if existing.
if (command.at(command.length() - 1) == ':')
command.erase(command.length() - 1, 1);
// Specially handling commands that Editor::execCommand does not directly
// support.
if (!command.compare("DeleteToEndOfParagraph")) {
DeleteToEndOfParagraph();
} else if(!command.compare("Indent")) {
GetEditor()->indent();
} else if(!command.compare("Outdent")) {
GetEditor()->outdent();
} else if(!command.compare("DeleteBackward")) {
WebCore::AtomicString editor_command("BackwardDelete");
GetEditor()->command(editor_command).execute();
} else if(!command.compare("DeleteForward")) {
WebCore::AtomicString editor_command("ForwardDelete");
GetEditor()->command(editor_command).execute();
} else {
WebCore::AtomicString editor_command(command.c_str());
GetEditor()->command(editor_command).execute();
}
return;
}
void WebTextInputImpl::SetMarkedText(const std::string& text,
int32_t location,
int32_t length) {
WebCore::Editor* editor = GetEditor();
WebCore::String str(text.c_str());
editor->confirmComposition(str);
WebCore::Frame* frame = GetFrame();
WTF::Vector<WebCore::CompositionUnderline> decorations;
editor->setComposition(str, decorations, location, length);
}
void WebTextInputImpl::UnMarkText() {
GetEditor()->confirmCompositionWithoutDisturbingSelection();;
}
bool WebTextInputImpl::HasMarkedText() {
return GetEditor()->hasComposition();
}
void WebTextInputImpl::ConversationIdentifier() {
}
void WebTextInputImpl::SubstringFromRange(int32_t location, int32_t length) {
}
void WebTextInputImpl::AttributedSubstringFromRange(int32_t location,
int32_t length) {
}
void WebTextInputImpl::MarkedRange(std::string* range_str) {
RefPtr<WebCore::Range> range = GetEditor()->compositionRange();
// Range::toString() returns a string different from what test expects.
// So we need to construct the string ourselves.
SStringPrintf(range_str, "%d,%d", range->startPosition().offset(),
range->endPosition().offset());
}
void WebTextInputImpl::SelectedRange(std::string* range_str) {
WTF::RefPtr<WebCore::Range> range
= GetFrame()->selectionController()->toRange();
// Range::toString() returns a string different from what test expects.
// So we need to construct the string ourselves.
SStringPrintf(range_str, "%d,%d", range.get()->startPosition().offset(),
range.get()->endPosition().offset());
}
void WebTextInputImpl::FirstRectForCharacterRange(int32_t location,
int32_t length) {
}
void WebTextInputImpl::CharacterIndexForPoint(double x, double y) {
}
void WebTextInputImpl::ValidAttributesForMarkedText(std::string* attributes) {
// We simply return a string with relevant keywords.
attributes->assign("NSUnderline,NSUnderlineColor,NSMarkedClauseSegment,NSTextInputReplacementRangeAttributeName");
}
void WebTextInputImpl::MakeAttributedString(const std::string& str) {
}
void WebTextInputImpl::DeleteToEndOfParagraph() {
WebCore::Editor* editor = GetEditor();
if (!editor->deleteWithDirection(WebCore::SelectionController::FORWARD,
WebCore::ParagraphBoundary,
true,
false)) {
editor->deleteWithDirection(WebCore::SelectionController::FORWARD,
WebCore::CharacterGranularity,
true,
false);
}
}
|