Update CefRange type to match gfx::Range (fixes #3422)
This commit is contained in:
parent
ae645e2362
commit
0782efb327
|
@ -42,13 +42,13 @@
|
|||
// way that may cause binary incompatibility with other builds. The universal
|
||||
// hash value will change if any platform is affected whereas the platform hash
|
||||
// values will change only if that particular platform is affected.
|
||||
#define CEF_API_HASH_UNIVERSAL "7c7515822b869395898c705bcc350222c26e8734"
|
||||
#define CEF_API_HASH_UNIVERSAL "42498212edc7b11d22aa6d1e5be14774d6156911"
|
||||
#if defined(OS_WIN)
|
||||
#define CEF_API_HASH_PLATFORM "54e2eed5aee11d5dbd88808a54f3e93a7bc17b0c"
|
||||
#define CEF_API_HASH_PLATFORM "4e102943a08b8fa0904dcc41801b8ae39eaca363"
|
||||
#elif defined(OS_MAC)
|
||||
#define CEF_API_HASH_PLATFORM "0f491b440d7e9e318146ed06cdeca86972e801c5"
|
||||
#define CEF_API_HASH_PLATFORM "d3710147ab507a38ab8652a3dd1d5ca81da0b234"
|
||||
#elif defined(OS_LINUX)
|
||||
#define CEF_API_HASH_PLATFORM "b5a01a70d1d15078988ca7d694c355503d5b5ad6"
|
||||
#define CEF_API_HASH_PLATFORM "308e5d6108ef34ec66be8a06b285582367dbc699"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -3000,8 +3000,8 @@ typedef enum {
|
|||
/// Structure representing a range.
|
||||
///
|
||||
typedef struct _cef_range_t {
|
||||
int from;
|
||||
int to;
|
||||
uint32_t from;
|
||||
uint32_t to;
|
||||
} cef_range_t;
|
||||
|
||||
///
|
||||
|
|
|
@ -215,7 +215,12 @@ class CefRange : public cef_range_t {
|
|||
public:
|
||||
CefRange() : cef_range_t{} {}
|
||||
CefRange(const cef_range_t& r) : cef_range_t(r) {}
|
||||
CefRange(int from, int to) : cef_range_t{from, to} {}
|
||||
CefRange(uint32_t from, uint32_t to) : cef_range_t{from, to} {}
|
||||
|
||||
static CefRange InvalidRange() {
|
||||
return CefRange(std::numeric_limits<uint32_t>::max(),
|
||||
std::numeric_limits<uint32_t>::max());
|
||||
}
|
||||
|
||||
void Set(int from_val, int to_val) { from = from_val, to = to_val; }
|
||||
};
|
||||
|
|
|
@ -35,12 +35,13 @@ bool IsSelectionAttribute(char attribute) {
|
|||
// to get the target range that's selected by the user in the current
|
||||
// composition string.
|
||||
void GetCompositionSelectionRange(HIMC imc,
|
||||
int* target_start,
|
||||
int* target_end) {
|
||||
int attribute_size = ::ImmGetCompositionString(imc, GCS_COMPATTR, nullptr, 0);
|
||||
uint32_t* target_start,
|
||||
uint32_t* target_end) {
|
||||
uint32_t attribute_size =
|
||||
::ImmGetCompositionString(imc, GCS_COMPATTR, nullptr, 0);
|
||||
if (attribute_size > 0) {
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
uint32_t start = 0;
|
||||
uint32_t end = 0;
|
||||
std::vector<char> attribute_data(attribute_size);
|
||||
|
||||
::ImmGetCompositionString(imc, GCS_COMPATTR, &attribute_data[0],
|
||||
|
@ -65,13 +66,13 @@ void GetCompositionSelectionRange(HIMC imc,
|
|||
// underlines information of the current composition string.
|
||||
void GetCompositionUnderlines(
|
||||
HIMC imc,
|
||||
int target_start,
|
||||
int target_end,
|
||||
uint32_t target_start,
|
||||
uint32_t target_end,
|
||||
std::vector<CefCompositionUnderline>& underlines) {
|
||||
int clause_size = ::ImmGetCompositionString(imc, GCS_COMPCLAUSE, nullptr, 0);
|
||||
int clause_length = clause_size / sizeof(uint32);
|
||||
if (clause_length) {
|
||||
std::vector<uint32> clause_data(clause_length);
|
||||
std::vector<uint32_t> clause_data(clause_length);
|
||||
|
||||
::ImmGetCompositionString(imc, GCS_COMPCLAUSE, &clause_data[0],
|
||||
clause_size);
|
||||
|
@ -99,7 +100,7 @@ OsrImeHandlerWin::OsrImeHandlerWin(HWND hwnd)
|
|||
: is_composing_(false),
|
||||
input_language_id_(LANG_USER_DEFAULT),
|
||||
system_caret_(false),
|
||||
cursor_index_(-1),
|
||||
cursor_index_(std::numeric_limits<uint32_t>::max()),
|
||||
hwnd_(hwnd) {
|
||||
ime_rect_ = {-1, -1, 0, 0};
|
||||
}
|
||||
|
@ -157,10 +158,10 @@ void OsrImeHandlerWin::MoveImeWindow() {
|
|||
}
|
||||
|
||||
CefRect rc = ime_rect_;
|
||||
int location = cursor_index_;
|
||||
uint32_t location = cursor_index_;
|
||||
|
||||
// If location is not specified fall back to the composition range start.
|
||||
if (location == -1) {
|
||||
if (location == std::numeric_limits<uint32_t>::max()) {
|
||||
location = composition_range_.from;
|
||||
}
|
||||
|
||||
|
@ -169,7 +170,7 @@ void OsrImeHandlerWin::MoveImeWindow() {
|
|||
location -= composition_range_.from;
|
||||
}
|
||||
|
||||
if (location < static_cast<int>(composition_bounds_.size())) {
|
||||
if (location < composition_bounds_.size()) {
|
||||
rc = composition_bounds_[location];
|
||||
} else {
|
||||
return;
|
||||
|
@ -240,7 +241,7 @@ void OsrImeHandlerWin::CleanupComposition() {
|
|||
void OsrImeHandlerWin::ResetComposition() {
|
||||
// Reset the composition status.
|
||||
is_composing_ = false;
|
||||
cursor_index_ = -1;
|
||||
cursor_index_ = std::numeric_limits<uint32_t>::max();
|
||||
}
|
||||
|
||||
void OsrImeHandlerWin::GetCompositionInfo(
|
||||
|
@ -253,11 +254,11 @@ void OsrImeHandlerWin::GetCompositionInfo(
|
|||
// convert them into underlines and selection range respectively.
|
||||
underlines.clear();
|
||||
|
||||
int length = static_cast<int>(composition_text.length());
|
||||
uint32_t length = static_cast<uint32_t>(composition_text.length());
|
||||
|
||||
// Find out the range selected by the user.
|
||||
int target_start = length;
|
||||
int target_end = length;
|
||||
uint32_t target_start = length;
|
||||
uint32_t target_end = length;
|
||||
if (lparam & GCS_COMPATTR) {
|
||||
GetCompositionSelectionRange(imc, &target_start, &target_end);
|
||||
}
|
||||
|
@ -386,7 +387,7 @@ void OsrImeHandlerWin::EnableIME() {
|
|||
::ImmAssociateContextEx(hwnd_, nullptr, IACE_DEFAULT);
|
||||
}
|
||||
|
||||
void OsrImeHandlerWin::UpdateCaretPosition(int index) {
|
||||
void OsrImeHandlerWin::UpdateCaretPosition(uint32_t index) {
|
||||
// Save the caret position.
|
||||
cursor_index_ = index;
|
||||
// Move the IME window.
|
||||
|
|
|
@ -60,7 +60,7 @@ class OsrImeHandlerWin {
|
|||
virtual void CancelIME();
|
||||
|
||||
// Updates the IME caret position of the given window.
|
||||
void UpdateCaretPosition(int index);
|
||||
void UpdateCaretPosition(uint32_t index);
|
||||
|
||||
// Updates the composition range. |selected_range| is the range of characters
|
||||
// that have been selected. |character_bounds| is the bounds of each character
|
||||
|
@ -100,7 +100,7 @@ class OsrImeHandlerWin {
|
|||
CefRect ime_rect_;
|
||||
|
||||
// The current cursor index in composition string.
|
||||
int cursor_index_;
|
||||
uint32_t cursor_index_;
|
||||
|
||||
// The composition range in the string. This may be used to determine the
|
||||
// offset in composition bounds.
|
||||
|
|
|
@ -418,8 +418,7 @@ void OsrWindowWin::OnIMEComposition(UINT message,
|
|||
// Send the text to the browser. The |replacement_range| and
|
||||
// |relative_cursor_pos| params are not used on Windows, so provide
|
||||
// default invalid values.
|
||||
browser_->GetHost()->ImeCommitText(cTextStr,
|
||||
CefRange(UINT32_MAX, UINT32_MAX), 0);
|
||||
browser_->GetHost()->ImeCommitText(cTextStr, CefRange::InvalidRange(), 0);
|
||||
ime_handler_->ResetComposition();
|
||||
// Continue reading the composition string - Japanese IMEs send both
|
||||
// GCS_RESULTSTR and GCS_COMPSTR.
|
||||
|
@ -433,7 +432,7 @@ void OsrWindowWin::OnIMEComposition(UINT message,
|
|||
// Send the composition string to the browser. The |replacement_range|
|
||||
// param is not used on Windows, so provide a default invalid value.
|
||||
browser_->GetHost()->ImeSetComposition(
|
||||
cTextStr, underlines, CefRange(UINT32_MAX, UINT32_MAX),
|
||||
cTextStr, underlines, CefRange::InvalidRange(),
|
||||
CefRange(composition_start,
|
||||
static_cast<int>(composition_start + cTextStr.length())));
|
||||
|
||||
|
|
|
@ -45,11 +45,12 @@ void ExtractUnderlines(NSAttributedString* string,
|
|||
color = CefColorFromNSColor(
|
||||
[colorAttr colorUsingColorSpaceName:NSDeviceRGBColorSpace]);
|
||||
}
|
||||
cef_composition_underline_t line = {{static_cast<int>(range.location),
|
||||
static_cast<int>(NSMaxRange(range))},
|
||||
color,
|
||||
0,
|
||||
[style intValue] > 1};
|
||||
cef_composition_underline_t line = {
|
||||
{static_cast<uint32_t>(range.location),
|
||||
static_cast<uint32_t>(NSMaxRange(range))},
|
||||
color,
|
||||
0,
|
||||
[style intValue] > 1};
|
||||
underlines->push_back(line);
|
||||
}
|
||||
i = static_cast<int>(range.location + range.length);
|
||||
|
@ -109,8 +110,8 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
|
|||
if (handlingKeyDown_) {
|
||||
textToBeInserted_.append([im_text UTF8String]);
|
||||
} else {
|
||||
cef_range_t range = {static_cast<int>(replacementRange.location),
|
||||
static_cast<int>(NSMaxRange(replacementRange))};
|
||||
cef_range_t range = {static_cast<uint32_t>(replacementRange.location),
|
||||
static_cast<uint32_t>(NSMaxRange(replacementRange))};
|
||||
browser_->GetHost()->ImeCommitText([im_text UTF8String], range, 0);
|
||||
}
|
||||
|
||||
|
@ -131,7 +132,7 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
|
|||
|
||||
BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];
|
||||
NSString* im_text = isAttributedString ? [aString string] : aString;
|
||||
int length = static_cast<int>([im_text length]);
|
||||
uint32_t length = [im_text length];
|
||||
|
||||
// |markedRange_| will get set in a callback from ImeSetComposition().
|
||||
selectedRange_ = newSelRange;
|
||||
|
@ -154,13 +155,14 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
|
|||
// ongoing composition when we send empty text.
|
||||
if (handlingKeyDown_) {
|
||||
setMarkedTextReplacementRange_ = {
|
||||
static_cast<int>(replacementRange.location),
|
||||
static_cast<int>(NSMaxRange(replacementRange))};
|
||||
static_cast<uint32_t>(replacementRange.location),
|
||||
static_cast<uint32_t>(NSMaxRange(replacementRange))};
|
||||
} else if (!handlingKeyDown_) {
|
||||
CefRange replacement_range(static_cast<int>(replacementRange.location),
|
||||
static_cast<int>(NSMaxRange(replacementRange)));
|
||||
CefRange selection_range(static_cast<int>(newSelRange.location),
|
||||
static_cast<int>(NSMaxRange(newSelRange)));
|
||||
CefRange replacement_range(
|
||||
static_cast<uint32_t>(replacementRange.location),
|
||||
static_cast<uint32_t>(NSMaxRange(replacementRange)));
|
||||
CefRange selection_range(static_cast<uint32_t>(newSelRange.location),
|
||||
static_cast<uint32_t>(NSMaxRange(newSelRange)));
|
||||
|
||||
browser_->GetHost()->ImeSetComposition(markedText_, underlines_,
|
||||
replacement_range, selection_range);
|
||||
|
@ -268,7 +270,7 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
|
|||
textToBeInserted_.clear();
|
||||
markedText_.clear();
|
||||
underlines_.clear();
|
||||
setMarkedTextReplacementRange_ = CefRange(UINT32_MAX, UINT32_MAX);
|
||||
setMarkedTextReplacementRange_ = CefRange::InvalidRange();
|
||||
unmarkTextCalled_ = NO;
|
||||
}
|
||||
|
||||
|
@ -306,7 +308,7 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
|
|||
if (textToBeInserted_.length() >
|
||||
((hasMarkedText_ || oldHasMarkedText_) ? 0u : 1u)) {
|
||||
browser_->GetHost()->ImeCommitText(textToBeInserted_,
|
||||
CefRange(UINT32_MAX, UINT32_MAX), 0);
|
||||
CefRange::InvalidRange(), 0);
|
||||
textToBeInserted_.clear();
|
||||
}
|
||||
|
||||
|
@ -317,8 +319,8 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
|
|||
// |selectedRange_| is the range being selected inside the marked text.
|
||||
browser_->GetHost()->ImeSetComposition(
|
||||
markedText_, underlines_, setMarkedTextReplacementRange_,
|
||||
CefRange(static_cast<int>(selectedRange_.location),
|
||||
static_cast<int>(NSMaxRange(selectedRange_))));
|
||||
CefRange(static_cast<uint32_t>(selectedRange_.location),
|
||||
static_cast<uint32_t>(NSMaxRange(selectedRange_))));
|
||||
} else if (oldHasMarkedText_ && !hasMarkedText_ && !textInserted) {
|
||||
// There was no marked text or inserted text. Complete or cancel the
|
||||
// composition.
|
||||
|
@ -329,7 +331,7 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
|
|||
}
|
||||
}
|
||||
|
||||
setMarkedTextReplacementRange_ = CefRange(UINT32_MAX, UINT32_MAX);
|
||||
setMarkedTextReplacementRange_ = CefRange::InvalidRange();
|
||||
}
|
||||
|
||||
- (void)ChangeCompositionRange:(CefRange)range
|
||||
|
|
|
@ -1097,8 +1097,8 @@ class OSRTestHandler : public RoutingTestHandler,
|
|||
const CefRange& range,
|
||||
const CefRenderHandler::RectList& bounds) override {
|
||||
if (test_type_ == OSR_TEST_IME_SET_COMPOSITION && started()) {
|
||||
EXPECT_EQ(range.from, 0);
|
||||
EXPECT_EQ(range.to, 1);
|
||||
EXPECT_EQ(range.from, 0U);
|
||||
EXPECT_EQ(range.to, 1U);
|
||||
EXPECT_EQ(1U, bounds.size());
|
||||
DestroySucceededTestSoon();
|
||||
}
|
||||
|
@ -1586,7 +1586,7 @@ class OSRTestHandler : public RoutingTestHandler,
|
|||
// This text should be honored instead of 'ka' added via key events
|
||||
CefString markedText("osrimecommit");
|
||||
|
||||
CefRange range(0, static_cast<int>(markedText.length()));
|
||||
CefRange range(0, static_cast<uint32_t>(markedText.length()));
|
||||
browser->GetHost()->ImeCommitText(markedText, range, 0);
|
||||
|
||||
ClickButtonToNavigate(browser);
|
||||
|
@ -1621,12 +1621,12 @@ class OSRTestHandler : public RoutingTestHandler,
|
|||
std::vector<CefCompositionUnderline> underlines;
|
||||
|
||||
// Use a thin black underline by default.
|
||||
CefRange range(0, static_cast<int>(markedText.length()));
|
||||
CefRange range(0, static_cast<uint32_t>(markedText.length()));
|
||||
cef_composition_underline_t line = {range, 0xFF000000, 0, false};
|
||||
underlines.push_back(line);
|
||||
|
||||
CefRange replacement_range(0, static_cast<int>(markedText.length()));
|
||||
CefRange selection_range(0, static_cast<int>(markedText.length()));
|
||||
CefRange replacement_range(0, static_cast<uint32_t>(markedText.length()));
|
||||
CefRange selection_range(0, static_cast<uint32_t>(markedText.length()));
|
||||
|
||||
// Composition should be updated
|
||||
browser->GetHost()->ImeSetComposition(markedText, underlines,
|
||||
|
@ -1646,12 +1646,12 @@ class OSRTestHandler : public RoutingTestHandler,
|
|||
std::vector<CefCompositionUnderline> underlines;
|
||||
|
||||
// Use a thin black underline by default.
|
||||
CefRange range(0, static_cast<int>(markedText.length()));
|
||||
CefRange range(0, static_cast<uint32_t>(markedText.length()));
|
||||
cef_composition_underline_t line = {range, 0xFF000000, 0, false};
|
||||
underlines.push_back(line);
|
||||
|
||||
CefRange replacement_range(0, static_cast<int>(markedText.length()));
|
||||
CefRange selection_range(0, static_cast<int>(markedText.length()));
|
||||
CefRange replacement_range(0, static_cast<uint32_t>(markedText.length()));
|
||||
CefRange selection_range(0, static_cast<uint32_t>(markedText.length()));
|
||||
|
||||
// This should update composition range and
|
||||
// trigger the compositionRangeChanged callback
|
||||
|
|
|
@ -64,12 +64,12 @@ void RunTextfieldContents(CefRefPtr<CefWindow> window) {
|
|||
|
||||
// Test select range.
|
||||
EXPECT_FALSE(textfield->HasSelection());
|
||||
EXPECT_EQ(
|
||||
CefRange(static_cast<int>(cursor_pos), static_cast<int>(cursor_pos)),
|
||||
textfield->GetSelectedRange());
|
||||
textfield->SelectRange(CefRange(0, static_cast<int>(cursor_pos)));
|
||||
EXPECT_EQ(CefRange(static_cast<uint32_t>(cursor_pos),
|
||||
static_cast<uint32_t>(cursor_pos)),
|
||||
textfield->GetSelectedRange());
|
||||
textfield->SelectRange(CefRange(0, static_cast<uint32_t>(cursor_pos)));
|
||||
EXPECT_TRUE(textfield->HasSelection());
|
||||
EXPECT_EQ(CefRange(0, static_cast<int>(cursor_pos)),
|
||||
EXPECT_EQ(CefRange(0, static_cast<uint32_t>(cursor_pos)),
|
||||
textfield->GetSelectedRange());
|
||||
EXPECT_STREQ(kText, textfield->GetSelectedText().ToString().c_str());
|
||||
EXPECT_EQ(cursor_pos, textfield->GetCursorPosition());
|
||||
|
@ -89,23 +89,23 @@ void RunTextfieldContents(CefRefPtr<CefWindow> window) {
|
|||
EXPECT_TRUE(textfield->HasSelection());
|
||||
|
||||
cursor_pos = sizeof(kReplaceText) + sizeof(kAppendText) - 2;
|
||||
EXPECT_EQ(CefRange(0, static_cast<int>(cursor_pos)),
|
||||
EXPECT_EQ(CefRange(0, static_cast<uint32_t>(cursor_pos)),
|
||||
textfield->GetSelectedRange());
|
||||
EXPECT_EQ(cursor_pos, textfield->GetCursorPosition());
|
||||
|
||||
// Test clear selection.
|
||||
textfield->ClearSelection();
|
||||
EXPECT_FALSE(textfield->HasSelection());
|
||||
EXPECT_EQ(
|
||||
CefRange(static_cast<int>(cursor_pos), static_cast<int>(cursor_pos)),
|
||||
textfield->GetSelectedRange());
|
||||
EXPECT_EQ(CefRange(static_cast<uint32_t>(cursor_pos),
|
||||
static_cast<uint32_t>(cursor_pos)),
|
||||
textfield->GetSelectedRange());
|
||||
EXPECT_EQ(cursor_pos, textfield->GetCursorPosition());
|
||||
|
||||
// Test selection with command.
|
||||
EXPECT_TRUE(textfield->IsCommandEnabled(CEF_TFC_SELECT_ALL));
|
||||
textfield->ExecuteCommand(CEF_TFC_SELECT_ALL);
|
||||
EXPECT_TRUE(textfield->HasSelection());
|
||||
EXPECT_EQ(CefRange(0, static_cast<int>(cursor_pos)),
|
||||
EXPECT_EQ(CefRange(0, static_cast<uint32_t>(cursor_pos)),
|
||||
textfield->GetSelectedRange());
|
||||
EXPECT_EQ(cursor_pos, textfield->GetCursorPosition());
|
||||
|
||||
|
|
Loading…
Reference in New Issue