Commit 7546d332 authored by thestig's avatar thestig Committed by Commit bot

Use container::back() and container::pop_back() in ui/

Also convert !container.size() to container.empty().

Review-Url: https://codereview.chromium.org/2126433002
Cr-Commit-Position: refs/heads/master@{#405289}
parent 47b22eb9
...@@ -283,8 +283,9 @@ void IMM32Manager::CompleteComposition(HWND window_handle, HIMC imm_context) { ...@@ -283,8 +283,9 @@ void IMM32Manager::CompleteComposition(HWND window_handle, HIMC imm_context) {
} }
} }
void IMM32Manager::GetCompositionInfo(HIMC imm_context, LPARAM lparam, void IMM32Manager::GetCompositionInfo(HIMC imm_context,
CompositionText* composition) { LPARAM lparam,
CompositionText* composition) {
// We only care about GCS_COMPATTR, GCS_COMPCLAUSE and GCS_CURSORPOS, and // We only care about GCS_COMPATTR, GCS_COMPCLAUSE and GCS_CURSORPOS, and
// convert them into underlines and selection range respectively. // convert them into underlines and selection range respectively.
composition->underlines.clear(); composition->underlines.clear();
...@@ -319,28 +320,29 @@ void IMM32Manager::GetCompositionInfo(HIMC imm_context, LPARAM lparam, ...@@ -319,28 +320,29 @@ void IMM32Manager::GetCompositionInfo(HIMC imm_context, LPARAM lparam,
} }
// Set default underlines in case there is no clause information. // Set default underlines in case there is no clause information.
if (!composition->underlines.size()) { if (!composition->underlines.empty())
CompositionUnderline underline; return;
underline.color = SK_ColorBLACK;
underline.background_color = SK_ColorTRANSPARENT; CompositionUnderline underline;
if (target_start > 0) { underline.color = SK_ColorBLACK;
underline.start_offset = 0U; underline.background_color = SK_ColorTRANSPARENT;
underline.end_offset = static_cast<uint32_t>(target_start); if (target_start > 0) {
underline.thick = false; underline.start_offset = 0U;
composition->underlines.push_back(underline); underline.end_offset = static_cast<uint32_t>(target_start);
} underline.thick = false;
if (target_end > target_start) { composition->underlines.push_back(underline);
underline.start_offset = static_cast<uint32_t>(target_start); }
underline.end_offset = static_cast<uint32_t>(target_end); if (target_end > target_start) {
underline.thick = true; underline.start_offset = static_cast<uint32_t>(target_start);
composition->underlines.push_back(underline); underline.end_offset = static_cast<uint32_t>(target_end);
} underline.thick = true;
if (target_end < length) { composition->underlines.push_back(underline);
underline.start_offset = static_cast<uint32_t>(target_end); }
underline.end_offset = static_cast<uint32_t>(length); if (target_end < length) {
underline.thick = false; underline.start_offset = static_cast<uint32_t>(target_end);
composition->underlines.push_back(underline); underline.end_offset = static_cast<uint32_t>(length);
} underline.thick = false;
composition->underlines.push_back(underline);
} }
} }
......
...@@ -19,7 +19,7 @@ void SetResult(const base::string16& result, ui::win::OpenFileName* ofn) { ...@@ -19,7 +19,7 @@ void SetResult(const base::string16& result, ui::win::OpenFileName* ofn) {
ADD_FAILURE() << "filename buffer insufficient."; ADD_FAILURE() << "filename buffer insufficient.";
return; return;
} }
if (!result.size()) { if (result.empty()) {
ofn->GetOPENFILENAME()->lpstrFile[0] = 0; ofn->GetOPENFILENAME()->lpstrFile[0] = 0;
} else { } else {
// Because the result has embedded nulls, we must memcpy. // Because the result has embedded nulls, we must memcpy.
......
...@@ -24,7 +24,7 @@ LayerAnimatorCollection::~LayerAnimatorCollection() { ...@@ -24,7 +24,7 @@ LayerAnimatorCollection::~LayerAnimatorCollection() {
void LayerAnimatorCollection::StartAnimator( void LayerAnimatorCollection::StartAnimator(
scoped_refptr<LayerAnimator> animator) { scoped_refptr<LayerAnimator> animator) {
DCHECK_EQ(0U, animators_.count(animator)); DCHECK_EQ(0U, animators_.count(animator));
if (!animators_.size()) if (animators_.empty())
last_tick_time_ = base::TimeTicks::Now(); last_tick_time_ = base::TimeTicks::Now();
animators_.insert(animator); animators_.insert(animator);
if (animators_.size() == 1U && compositor_) if (animators_.size() == 1U && compositor_)
......
...@@ -262,10 +262,8 @@ class ScreenMac : public Screen { ...@@ -262,10 +262,8 @@ class ScreenMac : public Screen {
} }
} }
if (!displays.size()) return displays.empty() ? std::vector<Display>(1, GetPrimaryDisplay())
return std::vector<Display>(1, GetPrimaryDisplay()); : displays;
return displays;
} }
// The displays currently attached to the device. // The displays currently attached to the device.
......
...@@ -20,8 +20,8 @@ namespace { ...@@ -20,8 +20,8 @@ namespace {
std::string FormatLog(const char* fmt, va_list args) { std::string FormatLog(const char* fmt, va_list args) {
std::string msg = base::StringPrintV(fmt, args); std::string msg = base::StringPrintV(fmt, args);
if (!msg.empty() && msg[msg.size() - 1] == '\n') if (!msg.empty() && msg.back() == '\n')
msg.erase(msg.end() - 1, msg.end()); msg.pop_back();
return msg; return msg;
} }
......
...@@ -14,8 +14,8 @@ namespace { ...@@ -14,8 +14,8 @@ namespace {
std::string FormatLog(const char* fmt, va_list args) { std::string FormatLog(const char* fmt, va_list args) {
std::string msg = base::StringPrintV(fmt, args); std::string msg = base::StringPrintV(fmt, args);
if (!msg.empty() && msg[msg.size() - 1] == '\n') if (!msg.empty() && msg.back() == '\n')
msg.erase(msg.end() - 1, msg.end()); msg.pop_back();
return msg; return msg;
} }
......
...@@ -1078,8 +1078,7 @@ void GesturePropertyProvider::ParseXorgConfFile(const std::string& content) { ...@@ -1078,8 +1078,7 @@ void GesturePropertyProvider::ParseXorgConfFile(const std::string& content) {
// one. // one.
if (is_parsing) { if (is_parsing) {
// Stop parsing the current line if the format is wrong. // Stop parsing the current line if the format is wrong.
if (piece.size() <= 2 || piece[0] != '\"' || if (piece.size() <= 2 || piece[0] != '\"' || piece.back() != '\"') {
piece[piece.size() - 1] != '\"') {
LOG(ERROR) << "Error parsing line: " << lines.token(); LOG(ERROR) << "Error parsing line: " << lines.token();
has_error = true; has_error = true;
if (next_is_section_type) if (next_is_section_type)
......
...@@ -295,8 +295,8 @@ TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) { ...@@ -295,8 +295,8 @@ TEST_F(NotificationListTest, OldPopupShouldNotBeHidden) {
} }
popups.clear(); popups.clear();
popups = GetPopups(); popups = GetPopups();
EXPECT_EQ(1u, popups.size()); ASSERT_EQ(1u, popups.size());
EXPECT_EQ(ids[ids.size() - 1], (*popups.begin())->id()); EXPECT_EQ(ids.back(), (*popups.begin())->id());
} }
TEST_F(NotificationListTest, Priority) { TEST_F(NotificationListTest, Priority) {
......
...@@ -96,7 +96,7 @@ void PopupTimersController::OnNotificationUpdated(const std::string& id) { ...@@ -96,7 +96,7 @@ void PopupTimersController::OnNotificationUpdated(const std::string& id) {
NotificationList::PopupNotifications popup_notifications = NotificationList::PopupNotifications popup_notifications =
message_center_->GetPopupNotifications(); message_center_->GetPopupNotifications();
if (!popup_notifications.size()) { if (popup_notifications.empty()) {
CancelAll(); CancelAll();
return; return;
} }
......
...@@ -95,7 +95,7 @@ std::unique_ptr<views::Border> MakeSeparatorBorder(int top, ...@@ -95,7 +95,7 @@ std::unique_ptr<views::Border> MakeSeparatorBorder(int top,
// message next to each other within a single column. // message next to each other within a single column.
class ItemView : public views::View { class ItemView : public views::View {
public: public:
ItemView(const message_center::NotificationItem& item); explicit ItemView(const message_center::NotificationItem& item);
~ItemView() override; ~ItemView() override;
// Overridden from views::View: // Overridden from views::View:
...@@ -435,7 +435,7 @@ void NotificationView::CreateOrUpdateMessageView( ...@@ -435,7 +435,7 @@ void NotificationView::CreateOrUpdateMessageView(
message_view_->SetText(text); message_view_->SetText(text);
} }
message_view_->SetVisible(!notification.items().size()); message_view_->SetVisible(notification.items().empty());
} }
base::string16 NotificationView::FormatContextMessage( base::string16 NotificationView::FormatContextMessage(
...@@ -545,7 +545,7 @@ void NotificationView::CreateOrUpdateProgressBarView( ...@@ -545,7 +545,7 @@ void NotificationView::CreateOrUpdateProgressBarView(
if (!is_indeterminate) if (!is_indeterminate)
progress_bar_view_->SetValue(notification.progress() / 100.0); progress_bar_view_->SetValue(notification.progress() / 100.0);
progress_bar_view_->SetVisible(!notification.items().size()); progress_bar_view_->SetVisible(notification.items().empty());
} }
void NotificationView::CreateOrUpdateListItemViews( void NotificationView::CreateOrUpdateListItemViews(
......
...@@ -278,7 +278,7 @@ std::vector<GammaRampRGBEntry> ResampleLut( ...@@ -278,7 +278,7 @@ std::vector<GammaRampRGBEntry> ResampleLut(
(lut_in[base_index + 1].b - lut_in[base_index].b) * (lut_in[base_index + 1].b - lut_in[base_index].b) *
remaining / desired_size; remaining / desired_size;
} else { } else {
result[i] = lut_in[lut_in.size() - 1]; result[i] = lut_in.back();
} }
} }
...@@ -304,8 +304,7 @@ class DrmDevice::PageFlipManager { ...@@ -304,8 +304,7 @@ class DrmDevice::PageFlipManager {
} }
DrmDevice::PageFlipCallback callback = it->callback; DrmDevice::PageFlipCallback callback = it->callback;
it->pending_calls -= 1; it->pending_calls--;
if (it->pending_calls) if (it->pending_calls)
return; return;
...@@ -329,11 +328,11 @@ class DrmDevice::PageFlipManager { ...@@ -329,11 +328,11 @@ class DrmDevice::PageFlipManager {
}; };
struct FindCallback { struct FindCallback {
FindCallback(uint64_t id) : id(id) {} explicit FindCallback(uint64_t id) : id(id) {}
bool operator()(const PageFlip& flip) const { return flip.id == id; } bool operator()(const PageFlip& flip) const { return flip.id == id; }
uint64_t id; const uint64_t id;
}; };
uint64_t next_id_; uint64_t next_id_;
......
...@@ -441,7 +441,7 @@ bool TextfieldModel::CanUndo() { ...@@ -441,7 +441,7 @@ bool TextfieldModel::CanUndo() {
} }
bool TextfieldModel::CanRedo() { bool TextfieldModel::CanRedo() {
if (!edit_history_.size()) if (edit_history_.empty())
return false; return false;
// There is no redo iff the current edit is the last element in the history. // There is no redo iff the current edit is the last element in the history.
EditHistory::iterator iter = current_edit_; EditHistory::iterator iter = current_edit_;
...@@ -464,7 +464,7 @@ bool TextfieldModel::Undo() { ...@@ -464,7 +464,7 @@ bool TextfieldModel::Undo() {
if (current_edit_ == edit_history_.begin()) if (current_edit_ == edit_history_.begin())
current_edit_ = edit_history_.end(); current_edit_ = edit_history_.end();
else else
current_edit_--; --current_edit_;
return old != text() || old_cursor != GetCursorPosition(); return old != text() || old_cursor != GetCursorPosition();
} }
...@@ -478,7 +478,7 @@ bool TextfieldModel::Redo() { ...@@ -478,7 +478,7 @@ bool TextfieldModel::Redo() {
if (current_edit_ == edit_history_.end()) if (current_edit_ == edit_history_.end())
current_edit_ = edit_history_.begin(); current_edit_ = edit_history_.begin();
else else
current_edit_ ++; ++current_edit_;
base::string16 old = text(); base::string16 old = text();
size_t old_cursor = GetCursorPosition(); size_t old_cursor = GetCursorPosition();
(*current_edit_)->Redo(this); (*current_edit_)->Redo(this);
...@@ -716,7 +716,7 @@ void TextfieldModel::ClearRedoHistory() { ...@@ -716,7 +716,7 @@ void TextfieldModel::ClearRedoHistory() {
return; return;
} }
EditHistory::iterator delete_start = current_edit_; EditHistory::iterator delete_start = current_edit_;
delete_start++; ++delete_start;
STLDeleteContainerPointers(delete_start, edit_history_.end()); STLDeleteContainerPointers(delete_start, edit_history_.end());
edit_history_.erase(delete_start, edit_history_.end()); edit_history_.erase(delete_start, edit_history_.end());
} }
...@@ -789,7 +789,7 @@ bool TextfieldModel::AddOrMergeEditHistory(Edit* edit) { ...@@ -789,7 +789,7 @@ bool TextfieldModel::AddOrMergeEditHistory(Edit* edit) {
DCHECK_EQ(1u, edit_history_.size()); DCHECK_EQ(1u, edit_history_.size());
current_edit_ = edit_history_.begin(); current_edit_ = edit_history_.begin();
} else { } else {
current_edit_++; ++current_edit_;
} }
return false; return false;
} }
......
...@@ -937,8 +937,8 @@ void GridLayout::SizeRowsAndColumns(bool layout, int width, int height, ...@@ -937,8 +937,8 @@ void GridLayout::SizeRowsAndColumns(bool layout, int width, int height,
LayoutElement::CalculateLocationsFromSize(&rows_); LayoutElement::CalculateLocationsFromSize(&rows_);
// We now know the preferred height, set it here. // We now know the preferred height, set it here.
pref->set_height(rows_[rows_.size() - 1]->Location() + pref->set_height(rows_.back()->Location() + rows_.back()->Size() +
rows_[rows_.size() - 1]->Size() + insets_.height()); insets_.height());
if (layout && height != pref->height()) { if (layout && height != pref->height()) {
// We're doing a layout, and the height differs from the preferred height, // We're doing a layout, and the height differs from the preferred height,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment