Update CefRange type to match gfx::Range (fixes #3422)

This commit is contained in:
Vladimir Kharitonov 2023-05-16 13:22:17 +03:00 committed by Marshall Greenblatt
parent cbd0dfcdee
commit 8381105f52
9 changed files with 74 additions and 67 deletions

View File

@ -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 "defb610a3c797b3636da085bd008fb24c46c8242"
#define CEF_API_HASH_UNIVERSAL "1b74f24b87efbeddb08fb75d41827ccb19b84f77"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "b47966e88841b7aa5546ead8a2021892d51886b1"
#define CEF_API_HASH_PLATFORM "b36fe9fcbae0d8691bb9124f6ec18daf6abd7da5"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "da69054d32deecf2476aeb30607036e074413730"
#define CEF_API_HASH_PLATFORM "1af96f9fcc63d812b95d4be22f66f78e4a9b03a4"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "00ed1b02f30b01ed1c841e1ef515f1b77f9832e6"
#define CEF_API_HASH_PLATFORM "5016f4b78232c528ba78c9ee656d85d4a6fe910a"
#endif
#ifdef __cplusplus

View File

@ -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;
///

View File

@ -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; }
};

View File

@ -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.

View File

@ -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.

View File

@ -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())));

View File

@ -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

View File

@ -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

View File

@ -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());