Convert gfx::Range to size_t.
This will allow us to avoid a large number of narrowing casts at callsites. Bug: 1292951 Change-Id: I78aa8a79d24d2fcffe1ac9589eff7034ce53aac3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3713409 Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Yuichiro Hanada <yhanada@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Danil Somsikov <dsv@chromium.org> Reviewed-by: Robert Sesek <rsesek@chromium.org> Commit-Queue: Peter Kasting <pkasting@chromium.org> Cr-Commit-Position: refs/heads/main@{#1018523}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
d81dcdf2f1
commit
43fddaaa4c
chrome/browser/ui/views/omnibox
components/exo
content/browser/devtools/protocol
pdf/loader
third_party/blink/renderer/core/frame
ui
@ -627,13 +627,13 @@ void OmniboxViewViews::SetTextAndSelectedRanges(
|
||||
// the cursor are visible. If possible given the prior guarantee, also
|
||||
// guarantees |kPadTrailing| chars of the text following the cursor are
|
||||
// visible.
|
||||
static const uint32_t kPadTrailing = 30;
|
||||
static const uint32_t kPadLeading = 10;
|
||||
static const size_t kPadTrailing = 30;
|
||||
static const size_t kPadLeading = 10;
|
||||
|
||||
// We use SetTextWithoutCaretBoundsChangeNotification() in order to avoid
|
||||
// triggering accessibility events multiple times.
|
||||
SetTextWithoutCaretBoundsChangeNotification(text, ranges[0].end());
|
||||
Scroll({0, std::min<size_t>(ranges[0].end() + kPadTrailing, text.size()),
|
||||
Scroll({0, std::min(ranges[0].end() + kPadTrailing, text.size()),
|
||||
ranges[0].end() - std::min(kPadLeading, ranges[0].end())});
|
||||
// Setting the primary selected range will also fire an appropriate final
|
||||
// accessibility event after the changes above.
|
||||
|
@ -130,9 +130,9 @@ void TextInput::SetCompositionText(const ui::CompositionText& composition) {
|
||||
// user has a selection, then we can assume the min value of the cursor_pos
|
||||
// range as the start of the composition, as the selection will be replaced
|
||||
// by the composition text being set.
|
||||
uint32_t composition_start = composition_range_.IsValid()
|
||||
? composition_range_.GetMin()
|
||||
: cursor_pos_.GetMin();
|
||||
size_t composition_start = cursor_pos_.IsValid() ? cursor_pos_.GetMin() : 0;
|
||||
if (composition_range_.IsValid())
|
||||
composition_start = composition_range_.GetMin();
|
||||
composition_range_ = gfx::Range(composition_start,
|
||||
composition_start + composition.text.size());
|
||||
delegate_->SetCompositionText(composition);
|
||||
|
@ -717,16 +717,15 @@ void InputHandler::ImeSetComposition(
|
||||
widget_host = target_host;
|
||||
}
|
||||
|
||||
// If replacement start and end are not specified, then they are -1,
|
||||
// If replacement start and end are not specified, then the range is invalid,
|
||||
// so no replacing will be done.
|
||||
int replacement_start_out = -1;
|
||||
int replacement_end_out = -1;
|
||||
gfx::Range replacement_range = gfx::Range::InvalidRange();
|
||||
|
||||
// Check if replacement_start and end parameters were passed in
|
||||
if (replacement_start.isJust()) {
|
||||
replacement_start_out = replacement_start.fromJust();
|
||||
replacement_range.set_start(replacement_start.fromJust());
|
||||
if (replacement_end.isJust()) {
|
||||
replacement_end_out = replacement_end.fromJust();
|
||||
replacement_range.set_end(replacement_end.fromJust());
|
||||
} else {
|
||||
callback->sendFailure(Response::InvalidParams(
|
||||
"Either both replacement start/end are specified or neither."));
|
||||
@ -740,9 +739,8 @@ void InputHandler::ImeSetComposition(
|
||||
widget_host->Focus();
|
||||
|
||||
widget_host->GetWidgetInputHandler()->ImeSetComposition(
|
||||
text16, std::vector<ui::ImeTextSpan>(),
|
||||
gfx::Range(replacement_start_out, replacement_end_out), selection_start,
|
||||
selection_end, std::move(closure));
|
||||
text16, std::vector<ui::ImeTextSpan>(), replacement_range,
|
||||
selection_start, selection_end, std::move(closure));
|
||||
}
|
||||
|
||||
void InputHandler::DispatchMouseEvent(
|
||||
|
@ -20,16 +20,16 @@ namespace chrome_pdf {
|
||||
|
||||
// This class collects a chunks of data into one data stream. Client can check
|
||||
// if data in certain range is available, and get missing chunks of data.
|
||||
template <uint32_t N>
|
||||
template <size_t N>
|
||||
class ChunkStream {
|
||||
public:
|
||||
static constexpr uint32_t kChunkSize = N;
|
||||
static constexpr size_t kChunkSize = N;
|
||||
using ChunkData = typename std::array<unsigned char, N>;
|
||||
|
||||
ChunkStream() {}
|
||||
~ChunkStream() {}
|
||||
|
||||
void SetChunkData(uint32_t chunk_index, std::unique_ptr<ChunkData> data) {
|
||||
void SetChunkData(size_t chunk_index, std::unique_ptr<ChunkData> data) {
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
@ -48,11 +48,11 @@ class ChunkStream {
|
||||
return false;
|
||||
|
||||
unsigned char* data_buffer = static_cast<unsigned char*>(buffer);
|
||||
uint32_t start = range.start();
|
||||
size_t start = range.start();
|
||||
while (start != range.end()) {
|
||||
const uint32_t chunk_index = GetChunkIndex(start);
|
||||
const uint32_t chunk_start = start % kChunkSize;
|
||||
const uint32_t len =
|
||||
const size_t chunk_index = GetChunkIndex(start);
|
||||
const size_t chunk_start = start % kChunkSize;
|
||||
const size_t len =
|
||||
std::min(kChunkSize - chunk_start, range.end() - start);
|
||||
memcpy(data_buffer, data_[chunk_index]->data() + chunk_start, len);
|
||||
data_buffer += len;
|
||||
@ -61,9 +61,9 @@ class ChunkStream {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t GetChunkIndex(uint32_t offset) const { return offset / kChunkSize; }
|
||||
size_t GetChunkIndex(size_t offset) const { return offset / kChunkSize; }
|
||||
|
||||
gfx::Range GetChunksRange(uint32_t offset, uint32_t size) const {
|
||||
gfx::Range GetChunksRange(size_t offset, size_t size) const {
|
||||
return gfx::Range(GetChunkIndex(offset), GetChunkEnd(offset + size));
|
||||
}
|
||||
|
||||
@ -81,12 +81,12 @@ class ChunkStream {
|
||||
return filled_chunks_.Contains(chunks_range);
|
||||
}
|
||||
|
||||
bool IsChunkAvailable(uint32_t chunk_index) const {
|
||||
bool IsChunkAvailable(size_t chunk_index) const {
|
||||
return filled_chunks_.Contains(chunk_index);
|
||||
}
|
||||
|
||||
void set_eof_pos(uint32_t eof_pos) { eof_pos_ = eof_pos; }
|
||||
uint32_t eof_pos() const { return eof_pos_; }
|
||||
void set_eof_pos(size_t eof_pos) { eof_pos_ = eof_pos; }
|
||||
size_t eof_pos() const { return eof_pos_; }
|
||||
|
||||
const RangeSet& filled_chunks() const { return filled_chunks_; }
|
||||
|
||||
@ -94,7 +94,7 @@ class ChunkStream {
|
||||
return eof_pos_ > 0 && IsRangeAvailable(gfx::Range(0, eof_pos_));
|
||||
}
|
||||
|
||||
bool IsValidChunkIndex(uint32_t chunk_index) const {
|
||||
bool IsValidChunkIndex(size_t chunk_index) const {
|
||||
return !eof_pos_ || (chunk_index <= GetChunkIndex(eof_pos_ - 1));
|
||||
}
|
||||
|
||||
@ -105,18 +105,18 @@ class ChunkStream {
|
||||
filled_chunks_count_ = 0;
|
||||
}
|
||||
|
||||
uint32_t filled_chunks_count() const { return filled_chunks_count_; }
|
||||
uint32_t total_chunks_count() const { return GetChunkEnd(eof_pos_); }
|
||||
size_t filled_chunks_count() const { return filled_chunks_count_; }
|
||||
size_t total_chunks_count() const { return GetChunkEnd(eof_pos_); }
|
||||
|
||||
private:
|
||||
uint32_t GetChunkEnd(uint32_t offset) const {
|
||||
size_t GetChunkEnd(size_t offset) const {
|
||||
return (offset + kChunkSize - 1) / kChunkSize;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<ChunkData>> data_;
|
||||
uint32_t eof_pos_ = 0;
|
||||
size_t eof_pos_ = 0;
|
||||
RangeSet filled_chunks_;
|
||||
uint32_t filled_chunks_count_ = 0;
|
||||
size_t filled_chunks_count_ = 0;
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -218,7 +218,7 @@ void DocumentLoaderImpl::ContinueDownload() {
|
||||
DCHECK(!IsDocumentComplete());
|
||||
DCHECK_GT(GetDocumentSize(), 0U);
|
||||
|
||||
const uint32_t range_start =
|
||||
const size_t range_start =
|
||||
pending_requests_.IsEmpty() ? 0 : pending_requests_.First().start();
|
||||
RangeSet candidates_for_request(
|
||||
gfx::Range(range_start, chunk_stream_.total_chunks_count()));
|
||||
@ -243,8 +243,8 @@ void DocumentLoaderImpl::ContinueDownload() {
|
||||
chunk_.Clear();
|
||||
is_partial_loader_active_ = true;
|
||||
|
||||
const uint32_t start = next_request.start() * DataStream::kChunkSize;
|
||||
const uint32_t length =
|
||||
const size_t start = next_request.start() * DataStream::kChunkSize;
|
||||
const size_t length =
|
||||
std::min(GetDocumentSize() - start,
|
||||
next_request.length() * DataStream::kChunkSize);
|
||||
|
||||
@ -330,8 +330,8 @@ bool DocumentLoaderImpl::SaveBuffer(char* input, uint32_t input_size) {
|
||||
if (chunk_.data_size == 0)
|
||||
chunk_.chunk_data = std::make_unique<DataStream::ChunkData>();
|
||||
|
||||
const uint32_t new_chunk_data_len =
|
||||
std::min(DataStream::kChunkSize - chunk_.data_size, input_size);
|
||||
const size_t new_chunk_data_len =
|
||||
std::min(DataStream::kChunkSize - chunk_.data_size, size_t{input_size});
|
||||
memcpy(chunk_.chunk_data->data() + chunk_.data_size, input,
|
||||
new_chunk_data_len);
|
||||
chunk_.data_size += new_chunk_data_len;
|
||||
@ -379,7 +379,7 @@ void DocumentLoaderImpl::ReadComplete() {
|
||||
if (chunk_.data_size != 0)
|
||||
SaveChunkData();
|
||||
} else {
|
||||
uint32_t eof = EndOfCurrentChunk();
|
||||
size_t eof = EndOfCurrentChunk();
|
||||
if (!chunk_stream_.filled_chunks().IsEmpty()) {
|
||||
eof = std::max(
|
||||
chunk_stream_.filled_chunks().Last().end() * DataStream::kChunkSize,
|
||||
|
@ -83,10 +83,10 @@ constexpr char kInvalidWorldID[] =
|
||||
"JavaScriptExecuteRequestInIsolatedWorld gets an invalid world id.";
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
uint32_t GetCurrentCursorPositionInFrame(LocalFrame* local_frame) {
|
||||
size_t GetCurrentCursorPositionInFrame(LocalFrame* local_frame) {
|
||||
blink::WebRange range =
|
||||
WebLocalFrameImpl::FromFrame(local_frame)->SelectionRange();
|
||||
return range.IsNull() ? 0U : static_cast<uint32_t>(range.StartOffset());
|
||||
return range.IsNull() ? size_t{0} : static_cast<size_t>(range.StartOffset());
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1155,12 +1155,13 @@ void LocalFrameMojoHandler::GetFirstRectForRange(const gfx::Range& range) {
|
||||
if (!pepper_has_caret) {
|
||||
// When request range is invalid we will try to obtain it from current
|
||||
// frame selection. The fallback value will be 0.
|
||||
uint32_t start = range.IsValid()
|
||||
size_t start = range.IsValid()
|
||||
? range.start()
|
||||
: GetCurrentCursorPositionInFrame(frame_);
|
||||
|
||||
WebLocalFrameImpl::FromFrame(frame_)->FirstRectForCharacterRange(
|
||||
start, range.length(), rect);
|
||||
base::checked_cast<unsigned>(start),
|
||||
base::checked_cast<unsigned>(range.length()), rect);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1173,7 +1174,8 @@ void LocalFrameMojoHandler::GetStringForRange(
|
||||
gfx::Point baseline_point;
|
||||
ui::mojom::blink::AttributedStringPtr attributed_string = nullptr;
|
||||
NSAttributedString* string = SubstringUtil::AttributedSubstringInRange(
|
||||
frame_, range.start(), range.length(), &baseline_point);
|
||||
frame_, base::checked_cast<WTF::wtf_size_t>(range.start()),
|
||||
base::checked_cast<WTF::wtf_size_t>(range.length()), &baseline_point);
|
||||
if (string)
|
||||
attributed_string = ui::mojom::blink::AttributedString::From(string);
|
||||
|
||||
|
@ -3361,7 +3361,8 @@ bool WebFrameWidgetImpl::SetComposition(
|
||||
return controller->SetComposition(
|
||||
text, ime_text_spans,
|
||||
replacement_range.IsValid()
|
||||
? WebRange(replacement_range.start(), replacement_range.length())
|
||||
? WebRange(base::checked_cast<int>(replacement_range.start()),
|
||||
base::checked_cast<int>(replacement_range.length()))
|
||||
: WebRange(),
|
||||
selection_start, selection_end);
|
||||
}
|
||||
@ -3377,7 +3378,8 @@ void WebFrameWidgetImpl::CommitText(
|
||||
controller->CommitText(
|
||||
text, ime_text_spans,
|
||||
replacement_range.IsValid()
|
||||
? WebRange(replacement_range.start(), replacement_range.length())
|
||||
? WebRange(base::checked_cast<int>(replacement_range.start()),
|
||||
base::checked_cast<int>(replacement_range.length()))
|
||||
: WebRange(),
|
||||
relative_cursor_pos);
|
||||
}
|
||||
|
@ -471,8 +471,8 @@ HRESULT TSFTextStore::InsertTextAtSelection(DWORD flags,
|
||||
LONG old_delta = (LONG)replace_text_range_.start() -
|
||||
(LONG)replace_text_range_.end() + replace_text_size_;
|
||||
LONG new_delta = start_pos - end_pos + text_buffer_size;
|
||||
replace_text_range_.set_start(
|
||||
std::min((uint32_t)start_pos, replace_text_range_.start()));
|
||||
replace_text_range_.set_start(std::min(static_cast<size_t>(start_pos),
|
||||
replace_text_range_.start()));
|
||||
// New replacement text ends after previous replacement text. We need to
|
||||
// use the new end after adjusting with previous delta.
|
||||
if ((uint32_t)end_pos >=
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/format_macros.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "build/build_config.h"
|
||||
#include "ui/gfx/ipc/geometry/gfx_param_traits.h"
|
||||
@ -21,8 +22,8 @@
|
||||
namespace IPC {
|
||||
|
||||
void ParamTraits<gfx::Range>::Write(base::Pickle* m, const gfx::Range& r) {
|
||||
m->WriteUInt32(r.start());
|
||||
m->WriteUInt32(r.end());
|
||||
m->WriteUInt32(static_cast<uint32_t>(r.start()));
|
||||
m->WriteUInt32(static_cast<uint32_t>(r.end()));
|
||||
}
|
||||
|
||||
bool ParamTraits<gfx::Range>::Read(const base::Pickle* m,
|
||||
@ -37,7 +38,7 @@ bool ParamTraits<gfx::Range>::Read(const base::Pickle* m,
|
||||
}
|
||||
|
||||
void ParamTraits<gfx::Range>::Log(const gfx::Range& r, std::string* l) {
|
||||
l->append(base::StringPrintf("(%d, %d)", r.start(), r.end()));
|
||||
l->append(base::StringPrintf("(%" PRIuS ", %" PRIuS ")", r.start(), r.end()));
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
|
@ -13,8 +13,12 @@ namespace mojo {
|
||||
|
||||
template <>
|
||||
struct StructTraits<gfx::mojom::RangeDataView, gfx::Range> {
|
||||
static uint32_t start(const gfx::Range& r) { return r.start(); }
|
||||
static uint32_t end(const gfx::Range& r) { return r.end(); }
|
||||
static uint32_t start(const gfx::Range& r) {
|
||||
return static_cast<uint32_t>(r.start());
|
||||
}
|
||||
static uint32_t end(const gfx::Range& r) {
|
||||
return static_cast<uint32_t>(r.end());
|
||||
}
|
||||
static bool Read(gfx::mojom::RangeDataView data, gfx::Range* out) {
|
||||
out->set_start(data.start());
|
||||
out->set_end(data.end());
|
||||
|
@ -46,14 +46,17 @@ class RangeStructTraitsTest : public testing::Test,
|
||||
} // namespace
|
||||
|
||||
TEST_F(RangeStructTraitsTest, Range) {
|
||||
const uint32_t start = 1234;
|
||||
const uint32_t end = 5678;
|
||||
const size_t start = 1234;
|
||||
const size_t end = 5678;
|
||||
gfx::Range input(start, end);
|
||||
mojo::Remote<mojom::RangeTraitsTestService> remote = GetTraitsTestRemote();
|
||||
gfx::Range output;
|
||||
remote->EchoRange(input, &output);
|
||||
EXPECT_EQ(start, output.start());
|
||||
EXPECT_EQ(end, output.end());
|
||||
|
||||
remote->EchoRange(gfx::Range::InvalidRange(), &output);
|
||||
EXPECT_FALSE(output.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(RangeStructTraitsTest, RangeF) {
|
||||
|
@ -6,12 +6,13 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "base/format_macros.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
std::string Range::ToString() const {
|
||||
return base::StringPrintf("{%" PRIu32 ",%" PRIu32 "}", start(), end());
|
||||
return base::StringPrintf("{%" PRIuS ",%" PRIuS "}", start(), end());
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Range& range) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "base/numerics/safe_conversions.h"
|
||||
#include "build/build_config.h"
|
||||
#include "ui/gfx/range/gfx_range_export.h"
|
||||
|
||||
@ -37,10 +38,12 @@ class GFX_RANGE_EXPORT Range {
|
||||
constexpr Range() : Range(0) {}
|
||||
|
||||
// Initializes the range with a start and end.
|
||||
constexpr Range(uint32_t start, uint32_t end) : start_(start), end_(end) {}
|
||||
constexpr Range(size_t start, size_t end)
|
||||
: start_(base::checked_cast<uint32_t>(start)),
|
||||
end_(base::checked_cast<uint32_t>(end)) {}
|
||||
|
||||
// Initializes the range with the same start and end positions.
|
||||
constexpr explicit Range(uint32_t position) : Range(position, position) {}
|
||||
constexpr explicit Range(size_t position) : Range(position, position) {}
|
||||
|
||||
// Platform constructors.
|
||||
#if BUILDFLAG(IS_APPLE)
|
||||
@ -52,27 +55,28 @@ class GFX_RANGE_EXPORT Range {
|
||||
return Range(std::numeric_limits<uint32_t>::max());
|
||||
}
|
||||
|
||||
// Checks if the range is valid through comparison to InvalidRange().
|
||||
// Checks if the range is valid through comparison to InvalidRange(). If this
|
||||
// is not valid, you must not call start()/end().
|
||||
constexpr bool IsValid() const { return *this != InvalidRange(); }
|
||||
|
||||
// Getters and setters.
|
||||
constexpr uint32_t start() const { return start_; }
|
||||
void set_start(uint32_t start) { start_ = start; }
|
||||
constexpr size_t start() const { return start_; }
|
||||
void set_start(size_t start) { start_ = base::checked_cast<uint32_t>(start); }
|
||||
|
||||
constexpr uint32_t end() const { return end_; }
|
||||
void set_end(uint32_t end) { end_ = end; }
|
||||
constexpr size_t end() const { return end_; }
|
||||
void set_end(size_t end) { end_ = base::checked_cast<uint32_t>(end); }
|
||||
|
||||
// Returns the absolute value of the length.
|
||||
constexpr uint32_t length() const { return GetMax() - GetMin(); }
|
||||
constexpr size_t length() const { return GetMax() - GetMin(); }
|
||||
|
||||
constexpr bool is_reversed() const { return start() > end(); }
|
||||
constexpr bool is_empty() const { return start() == end(); }
|
||||
|
||||
// Returns the minimum and maximum values.
|
||||
constexpr uint32_t GetMin() const {
|
||||
constexpr size_t GetMin() const {
|
||||
return start() < end() ? start() : end();
|
||||
}
|
||||
constexpr uint32_t GetMax() const {
|
||||
constexpr size_t GetMax() const {
|
||||
return start() > end() ? start() : end();
|
||||
}
|
||||
|
||||
@ -109,8 +113,8 @@ class GFX_RANGE_EXPORT Range {
|
||||
// If they don't intersect, it returns an InvalidRange().
|
||||
// The returned range is always empty or forward (never reversed).
|
||||
constexpr Range Intersect(const Range& range) const {
|
||||
const uint32_t min = std::max(GetMin(), range.GetMin());
|
||||
const uint32_t max = std::min(GetMax(), range.GetMax());
|
||||
const size_t min = std::max(GetMin(), range.GetMin());
|
||||
const size_t max = std::min(GetMax(), range.GetMax());
|
||||
return (min < max || Contains(range) || range.Contains(*this))
|
||||
? Range(min, max)
|
||||
: InvalidRange();
|
||||
@ -129,8 +133,7 @@ class GFX_RANGE_EXPORT Range {
|
||||
|
||||
private:
|
||||
// Note: we use uint32_t instead of size_t because this struct is sent over
|
||||
// IPC which could span 32 & 64 bit processes. This is fine since text spans
|
||||
// shouldn't exceed UINT32_MAX even on 64 bit builds.
|
||||
// IPC which could span 32 & 64 bit processes.
|
||||
uint32_t start_;
|
||||
uint32_t end_;
|
||||
};
|
||||
|
@ -22,8 +22,6 @@ Range& Range::operator=(const NSRange& range) {
|
||||
*this = InvalidRange();
|
||||
} else {
|
||||
set_start(range.location);
|
||||
// Don't overflow |end_|.
|
||||
DCHECK_LE(range.length, std::numeric_limits<size_t>::max() - start());
|
||||
set_end(start() + range.length);
|
||||
}
|
||||
return *this;
|
||||
|
@ -784,7 +784,7 @@ void RenderText::MoveCursor(BreakType break_type,
|
||||
|
||||
bool RenderText::SetSelection(const SelectionModel& model) {
|
||||
// Enforce valid selection model components.
|
||||
uint32_t text_length = static_cast<uint32_t>(text().length());
|
||||
size_t text_length = text().length();
|
||||
std::vector<Range> ranges = model.GetAllSelections();
|
||||
for (auto& range : ranges) {
|
||||
range = {std::min(range.start(), text_length),
|
||||
@ -810,7 +810,7 @@ bool RenderText::MoveCursorToPoint(const Point& point,
|
||||
}
|
||||
|
||||
bool RenderText::SelectRange(const Range& range, bool primary) {
|
||||
uint32_t text_length = static_cast<uint32_t>(text().length());
|
||||
size_t text_length = text().length();
|
||||
Range sel(std::min(range.start(), text_length),
|
||||
std::min(range.end(), text_length));
|
||||
// Allow selection bounds at valid indices amid multi-character graphemes.
|
||||
@ -1919,7 +1919,8 @@ int RenderText::GetLineContainingYCoord(float text_y) {
|
||||
bool RenderText::RangeContainsCaret(const Range& range,
|
||||
size_t caret_pos,
|
||||
LogicalCursorDirection caret_affinity) {
|
||||
// NB: exploits unsigned wraparound (WG14/N1124 section 6.2.5 paragraph 9).
|
||||
if (caret_pos == 0 && caret_affinity == CURSOR_BACKWARD)
|
||||
return false;
|
||||
size_t adjacent = (caret_affinity == CURSOR_BACKWARD) ?
|
||||
caret_pos - 1 : caret_pos + 1;
|
||||
return range.Contains(Range(caret_pos, adjacent));
|
||||
|
@ -679,8 +679,7 @@ class HarfBuzzLineBreaker {
|
||||
}
|
||||
|
||||
const size_t valid_end_pos = std::max(
|
||||
segment.char_range.start(),
|
||||
static_cast<uint32_t>(FindValidBoundaryBefore(text_, end_pos)));
|
||||
segment.char_range.start(), FindValidBoundaryBefore(text_, end_pos));
|
||||
if (end_pos != valid_end_pos) {
|
||||
end_pos = valid_end_pos;
|
||||
width = run.GetGlyphWidthForCharRange(
|
||||
@ -692,9 +691,8 @@ class HarfBuzzLineBreaker {
|
||||
// not separate surrogate pair or combining characters.
|
||||
// See RenderTextHarfBuzzTest.Multiline_MinWidth for an example.
|
||||
if (width == 0 && available_width_ == max_width_) {
|
||||
end_pos = std::min(
|
||||
segment.char_range.end(),
|
||||
static_cast<uint32_t>(FindValidBoundaryAfter(text_, end_pos + 1)));
|
||||
end_pos = std::min(segment.char_range.end(),
|
||||
FindValidBoundaryAfter(text_, end_pos + 1));
|
||||
}
|
||||
|
||||
return end_pos;
|
||||
|
@ -511,12 +511,14 @@ class RenderTextTest : public testing::Test {
|
||||
size_t logical_index = run_list->visual_to_logical(i);
|
||||
const internal::TextRunHarfBuzz& run = *run_list->runs()[logical_index];
|
||||
if (run.range.length() == 1) {
|
||||
result.append(base::StringPrintf("[%d]", run.range.start()));
|
||||
result.append(base::StringPrintf("[%" PRIuS "]", run.range.start()));
|
||||
} else if (run.font_params.is_rtl) {
|
||||
result.append(base::StringPrintf("[%d<-%d]", run.range.end() - 1,
|
||||
result.append(base::StringPrintf("[%" PRIuS "<-%" PRIuS "]",
|
||||
run.range.end() - 1,
|
||||
run.range.start()));
|
||||
} else {
|
||||
result.append(base::StringPrintf("[%d->%d]", run.range.start(),
|
||||
result.append(base::StringPrintf("[%" PRIuS "->%" PRIuS "]",
|
||||
run.range.start(),
|
||||
run.range.end() - 1));
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ std::string SelectionModel::ToString() const {
|
||||
for (auto selection : secondary_selections()) {
|
||||
str += ",";
|
||||
if (selection.is_empty())
|
||||
base::StringAppendF(&str, "%" PRIu32, selection.end());
|
||||
base::StringAppendF(&str, "%" PRIuS, selection.end());
|
||||
else
|
||||
str += selection.ToString();
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ Textfield* BridgedNativeWidgetTest::InstallTextField(const std::string& text) {
|
||||
}
|
||||
|
||||
NSString* BridgedNativeWidgetTest::GetActualText() {
|
||||
return GetViewStringForRange(ns_view_, NSMakeRange(0, NSUIntegerMax));
|
||||
return GetViewStringForRange(ns_view_, EmptyRange());
|
||||
}
|
||||
|
||||
NSString* BridgedNativeWidgetTest::GetActualSelectedText() {
|
||||
@ -582,7 +582,7 @@ NSString* BridgedNativeWidgetTest::GetActualSelectedText() {
|
||||
}
|
||||
|
||||
NSString* BridgedNativeWidgetTest::GetExpectedText() {
|
||||
return GetViewStringForRange(dummy_text_view_, NSMakeRange(0, NSUIntegerMax));
|
||||
return GetViewStringForRange(dummy_text_view_, EmptyRange());
|
||||
}
|
||||
|
||||
NSString* BridgedNativeWidgetTest::GetExpectedSelectedText() {
|
||||
|
@ -33,7 +33,7 @@ namespace views::examples {
|
||||
|
||||
namespace {
|
||||
|
||||
gfx::Range ClampRange(gfx::Range range, uint32_t max) {
|
||||
gfx::Range ClampRange(gfx::Range range, size_t max) {
|
||||
range.set_start(std::min(range.start(), max));
|
||||
range.set_end(std::min(range.end(), max));
|
||||
return range;
|
||||
|
Reference in New Issue
Block a user