summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam <jam@chromium.org>2016-02-09 17:49:25 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-10 01:50:44 +0000
commit1f0b47c4a982ab2076590d95937b89f892bd4552 (patch)
treeb03bdb57e0fea570590ffe66764623b7039142db
parent5458a1b5f82ef7a0d01fca7c7352cd7fe7ec5d9a (diff)
downloadchromium_src-1f0b47c4a982ab2076590d95937b89f892bd4552.zip
chromium_src-1f0b47c4a982ab2076590d95937b89f892bd4552.tar.gz
chromium_src-1f0b47c4a982ab2076590d95937b89f892bd4552.tar.bz2
Switch gfx::Range to use uint32_t instead of size_t.
This is because size_t's size depends on the architecture and we send gfx::Range over IPC. We need IPCs to match as we're now going to support 32 and 64 bit processes communicating on Android. This is split off from https://codereview.chromium.org/1619363002/. BUG=581409 Review URL: https://codereview.chromium.org/1671403002 Cr-Commit-Position: refs/heads/master@{#374568}
-rw-r--r--content/browser/renderer_host/render_widget_host_view_mac.mm3
-rw-r--r--ui/gfx/ipc/gfx_param_traits.cc10
-rw-r--r--ui/gfx/range/range.cc17
-rw-r--r--ui/gfx/range/range.h28
-rw-r--r--ui/gfx/render_text.cc8
-rw-r--r--ui/gfx/render_text_harfbuzz.cc8
-rw-r--r--ui/gfx/selection_model.h2
-rw-r--r--ui/views/controls/styled_label_unittest.cc31
-rw-r--r--ui/views/examples/multiline_example.cc2
-rw-r--r--ui/views/touchui/touch_selection_controller_impl_unittest.cc8
10 files changed, 66 insertions, 51 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index acc1c8a..a73a09f 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -1310,7 +1310,8 @@ bool RenderWidgetHostViewMac::GetLineBreakIndex(
// 75% of maximum height.
// TODO(nona): Check the threshold is reliable or not.
// TODO(nona): Bidi support.
- const size_t loop_end_idx = std::min(bounds.size(), range.end());
+ const size_t loop_end_idx =
+ std::min(bounds.size(), static_cast<size_t>(range.end()));
int max_height = 0;
int min_y_offset = std::numeric_limits<int32_t>::max();
for (size_t idx = range.start(); idx < loop_end_idx; ++idx) {
diff --git a/ui/gfx/ipc/gfx_param_traits.cc b/ui/gfx/ipc/gfx_param_traits.cc
index 68d8b3d..1e5d612 100644
--- a/ui/gfx/ipc/gfx_param_traits.cc
+++ b/ui/gfx/ipc/gfx_param_traits.cc
@@ -300,15 +300,15 @@ void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) {
}
void ParamTraits<gfx::Range>::Write(base::Pickle* m, const gfx::Range& r) {
- m->WriteSizeT(r.start());
- m->WriteSizeT(r.end());
+ m->WriteUInt32(r.start());
+ m->WriteUInt32(r.end());
}
bool ParamTraits<gfx::Range>::Read(const base::Pickle* m,
base::PickleIterator* iter,
gfx::Range* r) {
- size_t start, end;
- if (!iter->ReadSizeT(&start) || !iter->ReadSizeT(&end))
+ uint32_t start, end;
+ if (!iter->ReadUInt32(&start) || !iter->ReadUInt32(&end))
return false;
r->set_start(start);
r->set_end(end);
@@ -316,7 +316,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("(%" PRIuS ", %" PRIuS ")", r.start(), r.end()));
+ l->append(base::StringPrintf("(%d, %d)", r.start(), r.end()));
}
void ParamTraits<gfx::ScrollOffset>::Write(base::Pickle* m,
diff --git a/ui/gfx/range/range.cc b/ui/gfx/range/range.cc
index 1c3968a..a6475cb 100644
--- a/ui/gfx/range/range.cc
+++ b/ui/gfx/range/range.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include <limits>
-#include "base/format_macros.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
@@ -18,30 +17,30 @@ Range::Range()
end_(0) {
}
-Range::Range(size_t start, size_t end)
+Range::Range(uint32_t start, uint32_t end)
: start_(start),
end_(end) {
}
-Range::Range(size_t position)
+Range::Range(uint32_t position)
: start_(position),
end_(position) {
}
// static
const Range Range::InvalidRange() {
- return Range(std::numeric_limits<size_t>::max());
+ return Range(std::numeric_limits<uint32_t>::max());
}
bool Range::IsValid() const {
return *this != InvalidRange();
}
-size_t Range::GetMin() const {
+uint32_t Range::GetMin() const {
return std::min(start(), end());
}
-size_t Range::GetMax() const {
+uint32_t Range::GetMax() const {
return std::max(start(), end());
}
@@ -68,8 +67,8 @@ bool Range::Contains(const Range& range) const {
}
Range Range::Intersect(const Range& range) const {
- size_t min = std::max(GetMin(), range.GetMin());
- size_t max = std::min(GetMax(), range.GetMax());
+ uint32_t min = std::max(GetMin(), range.GetMin());
+ uint32_t max = std::min(GetMax(), range.GetMax());
if (min >= max) // No intersection.
return InvalidRange();
@@ -78,7 +77,7 @@ Range Range::Intersect(const Range& range) const {
}
std::string Range::ToString() const {
- return base::StringPrintf("{%" PRIuS ",%" PRIuS "}", start(), end());
+ return base::StringPrintf("{%d,%d}", start(), end());
}
std::ostream& operator<<(std::ostream& os, const Range& range) {
diff --git a/ui/gfx/range/range.h b/ui/gfx/range/range.h
index 741b318..c99ca22 100644
--- a/ui/gfx/range/range.h
+++ b/ui/gfx/range/range.h
@@ -6,6 +6,7 @@
#define UI_GFX_RANGE_RANGE_H_
#include <stddef.h>
+#include <stdint.h>
#include <ostream>
#include <string>
@@ -39,10 +40,10 @@ class GFX_EXPORT Range {
Range();
// Initializes the range with a start and end.
- Range(size_t start, size_t end);
+ Range(uint32_t start, uint32_t end);
// Initializes the range with the same start and end positions.
- explicit Range(size_t position);
+ explicit Range(uint32_t position);
// Platform constructors.
#if defined(OS_MACOSX)
@@ -53,31 +54,30 @@ class GFX_EXPORT Range {
Range(const CHARRANGE& range, LONG total_length = -1);
#endif
- // Returns a range that is invalid, which is {size_t_max,size_t_max}.
+ // Returns a range that is invalid, which is {UINT32_MAX,UINT32_MAX}.
static const Range InvalidRange();
// Checks if the range is valid through comparison to InvalidRange().
bool IsValid() const;
// Getters and setters.
- size_t start() const { return start_; }
- void set_start(size_t start) { start_ = start; }
+ uint32_t start() const { return start_; }
+ void set_start(uint32_t start) { start_ = start; }
- size_t end() const { return end_; }
- void set_end(size_t end) { end_ = end; }
+ uint32_t end() const { return end_; }
+ void set_end(uint32_t end) { end_ = end; }
// Returns the absolute value of the length.
- size_t length() const {
- ptrdiff_t length = end() - start();
- return length >= 0 ? length : -length;
+ uint32_t length() const {
+ return GetMax() - GetMin();
}
bool is_reversed() const { return start() > end(); }
bool is_empty() const { return start() == end(); }
// Returns the minimum and maximum values.
- size_t GetMin() const;
- size_t GetMax() const;
+ uint32_t GetMin() const;
+ uint32_t GetMax() const;
bool operator==(const Range& other) const;
bool operator!=(const Range& other) const;
@@ -108,8 +108,8 @@ class GFX_EXPORT Range {
std::string ToString() const;
private:
- size_t start_;
- size_t end_;
+ uint32_t start_;
+ uint32_t end_;
};
GFX_EXPORT std::ostream& operator<<(std::ostream& os, const Range& range);
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 1757575..4a59924 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -632,7 +632,8 @@ void RenderText::MoveCursor(BreakType break_type,
bool RenderText::MoveCursorTo(const SelectionModel& model) {
// Enforce valid selection model components.
size_t text_length = text().length();
- Range range(std::min(model.selection().start(), text_length),
+ Range range(std::min(model.selection().start(),
+ static_cast<uint32_t>(text_length)),
std::min(model.caret_pos(), text_length));
// The current model only supports caret positions at valid cursor indices.
if (!IsValidCursorIndex(range.start()) || !IsValidCursorIndex(range.end()))
@@ -644,8 +645,9 @@ bool RenderText::MoveCursorTo(const SelectionModel& model) {
}
bool RenderText::SelectRange(const Range& range) {
- Range sel(std::min(range.start(), text().length()),
- std::min(range.end(), text().length()));
+ uint32_t text_length = static_cast<uint32_t>(text().length());
+ Range sel(std::min(range.start(), text_length),
+ std::min(range.end(), text_length));
// Allow selection bounds at valid indicies amid multi-character graphemes.
if (!IsValidLogicalIndex(sel.start()) || !IsValidLogicalIndex(sel.end()))
return false;
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
index 39fc88c..a9a05ef 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -460,7 +460,8 @@ class HarfBuzzLineBreaker {
}
const size_t valid_end_pos = std::max(
- segment.char_range.start(), FindValidBoundaryBefore(text_, end_pos));
+ segment.char_range.start(),
+ static_cast<uint32_t>(FindValidBoundaryBefore(text_, end_pos)));
if (end_pos != valid_end_pos) {
end_pos = valid_end_pos;
width = run.GetGlyphWidthForCharRange(
@@ -472,8 +473,9 @@ class HarfBuzzLineBreaker {
// not separate surrogate pair or combining characters.
// See RenderTextTest.Multiline_MinWidth for an example.
if (width == 0 && available_width_ == max_width_) {
- end_pos = std::min(segment.char_range.end(),
- FindValidBoundaryAfter(text_, end_pos + 1));
+ end_pos = std::min(
+ segment.char_range.end(),
+ static_cast<uint32_t>(FindValidBoundaryAfter(text_, end_pos + 1)));
}
return end_pos;
diff --git a/ui/gfx/selection_model.h b/ui/gfx/selection_model.h
index 87a7a2d..73bf113 100644
--- a/ui/gfx/selection_model.h
+++ b/ui/gfx/selection_model.h
@@ -77,7 +77,7 @@ class GFX_EXPORT SelectionModel {
// WARNING: Generally the selection start should not be changed without
// considering the effect on the caret affinity.
- void set_selection_start(size_t pos) { selection_.set_start(pos); }
+ void set_selection_start(uint32_t pos) { selection_.set_start(pos); }
bool operator==(const SelectionModel& sel) const;
bool operator!=(const SelectionModel& sel) const { return !(*this == sel); }
diff --git a/ui/views/controls/styled_label_unittest.cc b/ui/views/controls/styled_label_unittest.cc
index 3c0a7e7..cae7f67 100644
--- a/ui/views/controls/styled_label_unittest.cc
+++ b/ui/views/controls/styled_label_unittest.cc
@@ -184,7 +184,8 @@ TEST_F(StyledLabelTest, DontBreakLinks) {
const std::string link_text("and this should be a link");
InitStyledLabel(text + link_text);
styled()->AddStyleRange(
- gfx::Range(text.size(), text.size() + link_text.size()),
+ gfx::Range(static_cast<uint32_t>(text.size()),
+ static_cast<uint32_t>(text.size() + link_text.size())),
StyledLabel::RangeStyleInfo::CreateForLink());
Label label(ASCIIToUTF16(text + link_text.substr(0, link_text.size() / 2)));
@@ -209,7 +210,8 @@ TEST_F(StyledLabelTest, StyledRangeWithDisabledLineWrapping) {
StyledLabel::RangeStyleInfo style_info;
style_info.disable_line_wrapping = true;
styled()->AddStyleRange(
- gfx::Range(text.size(), text.size() + unbreakable_text.size()),
+ gfx::Range(static_cast<uint32_t>(text.size()),
+ static_cast<uint32_t>(text.size() + unbreakable_text.size())),
style_info);
Label label(ASCIIToUTF16(
@@ -233,7 +235,8 @@ TEST_F(StyledLabelTest, StyledRangeUnderlined) {
StyledLabel::RangeStyleInfo style_info;
style_info.font_style = gfx::Font::UNDERLINE;
styled()->AddStyleRange(
- gfx::Range(text.size(), text.size() + underlined_text.size()),
+ gfx::Range(static_cast<uint32_t>(text.size()),
+ static_cast<uint32_t>(text.size() + underlined_text.size())),
style_info);
styled()->SetBounds(0, 0, 1000, 1000);
@@ -255,7 +258,8 @@ TEST_F(StyledLabelTest, StyledRangeBold) {
StyledLabel::RangeStyleInfo style_info;
style_info.font_style = gfx::Font::BOLD;
- styled()->AddStyleRange(gfx::Range(0, bold_text.size()), style_info);
+ styled()->AddStyleRange(
+ gfx::Range(0u, static_cast<uint32_t>(bold_text.size())), style_info);
// Calculate the bold text width if it were a pure label view, both with bold
// and normal style.
@@ -315,13 +319,15 @@ TEST_F(StyledLabelTest, Color) {
StyledLabel::RangeStyleInfo style_info_red;
style_info_red.color = SK_ColorRED;
- styled()->AddStyleRange(gfx::Range(0, text_red.size()), style_info_red);
+ styled()->AddStyleRange(
+ gfx::Range(0u, static_cast<uint32_t>(text_red.size())), style_info_red);
StyledLabel::RangeStyleInfo style_info_link =
StyledLabel::RangeStyleInfo::CreateForLink();
- styled()->AddStyleRange(gfx::Range(text_red.size(),
- text_red.size() + text_link.size()),
- style_info_link);
+ styled()->AddStyleRange(
+ gfx::Range(static_cast<uint32_t>(text_red.size()),
+ static_cast<uint32_t>(text_red.size() + text_link.size())),
+ style_info_link);
styled()->SetBounds(0, 0, 1000, 1000);
styled()->Layout();
@@ -377,10 +383,13 @@ TEST_F(StyledLabelTest, StyledRangeWithTooltip) {
StyledLabel::RangeStyleInfo tooltip_style;
tooltip_style.tooltip = ASCIIToUTF16("tooltip");
styled()->AddStyleRange(
- gfx::Range(tooltip_start, tooltip_start + tooltip_text.size()),
+ gfx::Range(static_cast<uint32_t>(tooltip_start),
+ static_cast<uint32_t>(tooltip_start + tooltip_text.size())),
tooltip_style);
- styled()->AddStyleRange(gfx::Range(link_start, link_start + link_text.size()),
- StyledLabel::RangeStyleInfo::CreateForLink());
+ styled()->AddStyleRange(
+ gfx::Range(static_cast<uint32_t>(link_start),
+ static_cast<uint32_t>(link_start + link_text.size())),
+ StyledLabel::RangeStyleInfo::CreateForLink());
// Break line inside the range with the tooltip.
Label label(ASCIIToUTF16(
diff --git a/ui/views/examples/multiline_example.cc b/ui/views/examples/multiline_example.cc
index 5ce1a1b..d01b31e 100644
--- a/ui/views/examples/multiline_example.cc
+++ b/ui/views/examples/multiline_example.cc
@@ -25,7 +25,7 @@ namespace examples {
namespace {
-gfx::Range ClampRange(gfx::Range range, size_t max) {
+gfx::Range ClampRange(gfx::Range range, uint32_t max) {
range.set_start(std::min(range.start(), max));
range.set_end(std::min(range.end(), max));
return range;
diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
index 06ab5f4..3bdbbd5 100644
--- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc
+++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
@@ -553,13 +553,15 @@ TEST_F(TouchSelectionControllerImplTest,
textfield_->OnGestureEvent(&tap);
// Select some text such that one handle is hidden.
- textfield_->SelectRange(gfx::Range(10, textfield_text.length()));
+ textfield_->SelectRange(
+ gfx::Range(10u, static_cast<uint32_t>(textfield_text.length())));
// Check that one selection handle is hidden.
EXPECT_FALSE(IsSelectionHandle1Visible());
EXPECT_TRUE(IsSelectionHandle2Visible());
- EXPECT_EQ(gfx::Range(10, textfield_text.length()),
- textfield_->GetSelectedRange());
+ EXPECT_EQ(
+ gfx::Range(10u, static_cast<uint32_t>(textfield_text.length())),
+ textfield_->GetSelectedRange());
// Drag the visible handle around and make sure the selection end point of the
// invisible handle does not change.