Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_win.cc

Issue 6539002: Begun the DCHECK() cleanup. Starting off with /src/chrome/a* and /src/chrome/... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <locale> 8 #include <locale>
9 #include <string> 9 #include <string>
10 10
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // Returns a lazily initialized property bag accessor for saving our state in a 350 // Returns a lazily initialized property bag accessor for saving our state in a
351 // TabContents. 351 // TabContents.
352 PropertyAccessor<AutocompleteEditState>* GetStateAccessor() { 352 PropertyAccessor<AutocompleteEditState>* GetStateAccessor() {
353 static PropertyAccessor<AutocompleteEditState> state; 353 static PropertyAccessor<AutocompleteEditState> state;
354 return &state; 354 return &state;
355 } 355 }
356 356
357 class PaintPatcher { 357 class PaintPatcher {
358 public: 358 public:
359 PaintPatcher() : refcount_(0) { } 359 PaintPatcher() : refcount_(0) { }
360 ~PaintPatcher() { DCHECK(refcount_ == 0); } 360 ~PaintPatcher() { DCHECK_EQ(refcount_, 0); }
Robert Sesek 2011/02/17 19:57:02 This needs to be '0U' instead of just 0. I'll make
361 361
362 void RefPatch() { 362 void RefPatch() {
363 if (refcount_ == 0) { 363 if (refcount_ == 0) {
364 DCHECK(!begin_paint_.is_patched()); 364 DCHECK(!begin_paint_.is_patched());
365 DCHECK(!end_paint_.is_patched()); 365 DCHECK(!end_paint_.is_patched());
366 begin_paint_.Patch(L"riched20.dll", "user32.dll", "BeginPaint", 366 begin_paint_.Patch(L"riched20.dll", "user32.dll", "BeginPaint",
367 &BeginPaintIntercept); 367 &BeginPaintIntercept);
368 end_paint_.Patch(L"riched20.dll", "user32.dll", "EndPaint", 368 end_paint_.Patch(L"riched20.dll", "user32.dll", "EndPaint",
369 &EndPaintIntercept); 369 &EndPaintIntercept);
370 } 370 }
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 } 1052 }
1053 1053
1054 bool AutocompleteEditViewWin::IsItemForCommandIdDynamic(int command_id) const { 1054 bool AutocompleteEditViewWin::IsItemForCommandIdDynamic(int command_id) const {
1055 // No need to change the default IDS_PASTE_AND_GO label unless this is a 1055 // No need to change the default IDS_PASTE_AND_GO label unless this is a
1056 // search. 1056 // search.
1057 return command_id == IDS_PASTE_AND_GO; 1057 return command_id == IDS_PASTE_AND_GO;
1058 } 1058 }
1059 1059
1060 string16 AutocompleteEditViewWin::GetLabelForCommandId( 1060 string16 AutocompleteEditViewWin::GetLabelForCommandId(
1061 int command_id) const { 1061 int command_id) const {
1062 DCHECK(command_id == IDS_PASTE_AND_GO); 1062 DCHECK_EQ(command_id, IDS_PASTE_AND_GO);
1063 return l10n_util::GetStringUTF16(model_->is_paste_and_search() ? 1063 return l10n_util::GetStringUTF16(model_->is_paste_and_search() ?
1064 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); 1064 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
1065 } 1065 }
1066 1066
1067 void AutocompleteEditViewWin::ExecuteCommand(int command_id) { 1067 void AutocompleteEditViewWin::ExecuteCommand(int command_id) {
1068 ScopedFreeze freeze(this, GetTextObjectModel()); 1068 ScopedFreeze freeze(this, GetTextObjectModel());
1069 if (command_id == IDS_PASTE_AND_GO) { 1069 if (command_id == IDS_PASTE_AND_GO) {
1070 // This case is separate from the switch() below since we don't want to wrap 1070 // This case is separate from the switch() below since we don't want to wrap
1071 // it in OnBefore/AfterPossibleChange() calls. 1071 // it in OnBefore/AfterPossibleChange() calls.
1072 model_->PasteAndGo(); 1072 model_->PasteAndGo();
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
2031 2031
2032 void AutocompleteEditViewWin::GetSelection(CHARRANGE& sel) const { 2032 void AutocompleteEditViewWin::GetSelection(CHARRANGE& sel) const {
2033 GetSel(sel); 2033 GetSel(sel);
2034 2034
2035 // See if we need to reverse the direction of the selection. 2035 // See if we need to reverse the direction of the selection.
2036 ITextDocument* const text_object_model = GetTextObjectModel(); 2036 ITextDocument* const text_object_model = GetTextObjectModel();
2037 if (!text_object_model) 2037 if (!text_object_model)
2038 return; 2038 return;
2039 ScopedComPtr<ITextSelection> selection; 2039 ScopedComPtr<ITextSelection> selection;
2040 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); 2040 const HRESULT hr = text_object_model->GetSelection(selection.Receive());
2041 DCHECK(hr == S_OK); 2041 DCHECK_EQ(hr, S_OK);
2042 long flags; 2042 long flags;
2043 selection->GetFlags(&flags); 2043 selection->GetFlags(&flags);
2044 if (flags & tomSelStartActive) 2044 if (flags & tomSelStartActive)
2045 std::swap(sel.cpMin, sel.cpMax); 2045 std::swap(sel.cpMin, sel.cpMax);
2046 } 2046 }
2047 2047
2048 string16 AutocompleteEditViewWin::GetSelectedText() const { 2048 string16 AutocompleteEditViewWin::GetSelectedText() const {
2049 // Figure out the length of the selection. 2049 // Figure out the length of the selection.
2050 CHARRANGE sel; 2050 CHARRANGE sel;
2051 GetSel(sel); 2051 GetSel(sel);
2052 2052
2053 // Grab the selected text. 2053 // Grab the selected text.
2054 string16 str; 2054 string16 str;
2055 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); 2055 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1));
2056 return str; 2056 return str;
2057 } 2057 }
2058 2058
2059 void AutocompleteEditViewWin::SetSelection(LONG start, LONG end) { 2059 void AutocompleteEditViewWin::SetSelection(LONG start, LONG end) {
2060 SetSel(start, end); 2060 SetSel(start, end);
2061 2061
2062 if (start <= end) 2062 if (start <= end)
2063 return; 2063 return;
2064 2064
2065 // We need to reverse the direction of the selection. 2065 // We need to reverse the direction of the selection.
2066 ITextDocument* const text_object_model = GetTextObjectModel(); 2066 ITextDocument* const text_object_model = GetTextObjectModel();
2067 if (!text_object_model) 2067 if (!text_object_model)
2068 return; 2068 return;
2069 ScopedComPtr<ITextSelection> selection; 2069 ScopedComPtr<ITextSelection> selection;
2070 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); 2070 const HRESULT hr = text_object_model->GetSelection(selection.Receive());
2071 DCHECK(hr == S_OK); 2071 DCHECK_EQ(hr, S_OK);
2072 selection->SetFlags(tomSelStartActive); 2072 selection->SetFlags(tomSelStartActive);
2073 } 2073 }
2074 2074
2075 void AutocompleteEditViewWin::PlaceCaretAt(string16::size_type pos) { 2075 void AutocompleteEditViewWin::PlaceCaretAt(string16::size_type pos) {
2076 SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos)); 2076 SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos));
2077 } 2077 }
2078 2078
2079 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const { 2079 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const {
2080 const int text_length = GetTextLength(); 2080 const int text_length = GetTextLength();
2081 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) || 2081 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) ||
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 2297
2298 // Now copy what we drew to the target HDC. 2298 // Now copy what we drew to the target HDC.
2299 canvas.getTopPlatformDevice().drawToHDC(hdc, 2299 canvas.getTopPlatformDevice().drawToHDC(hdc,
2300 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, 2300 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left,
2301 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - 2301 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top -
2302 canvas_clip_rect.top, &canvas_paint_clip_rect); 2302 canvas_clip_rect.top, &canvas_paint_clip_rect);
2303 } 2303 }
2304 2304
2305 void AutocompleteEditViewWin::DrawDropHighlight( 2305 void AutocompleteEditViewWin::DrawDropHighlight(
2306 HDC hdc, const CRect& client_rect, const CRect& paint_clip_rect) { 2306 HDC hdc, const CRect& client_rect, const CRect& paint_clip_rect) {
2307 DCHECK(drop_highlight_position_ != -1); 2307 DCHECK_NE(drop_highlight_position_, -1);
2308 2308
2309 const int highlight_y = client_rect.top + font_y_adjustment_; 2309 const int highlight_y = client_rect.top + font_y_adjustment_;
2310 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1; 2310 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1;
2311 const CRect highlight_rect(highlight_x, 2311 const CRect highlight_rect(highlight_x,
2312 highlight_y, 2312 highlight_y,
2313 highlight_x + 1, 2313 highlight_x + 1,
2314 highlight_y + font_.GetHeight()); 2314 highlight_y + font_.GetHeight());
2315 2315
2316 // Clip the highlight to the region being painted. 2316 // Clip the highlight to the region being painted.
2317 CRect clip_rect; 2317 CRect clip_rect;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 // PosFromChar(i) might return 0 when i is greater than 1. 2580 // PosFromChar(i) might return 0 when i is greater than 1.
2581 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2581 return font_.GetStringWidth(text) + GetHorizontalMargin();
2582 } 2582 }
2583 2583
2584 bool AutocompleteEditViewWin::IsCaretAtEnd() const { 2584 bool AutocompleteEditViewWin::IsCaretAtEnd() const {
2585 long length = GetTextLength(); 2585 long length = GetTextLength();
2586 CHARRANGE sel; 2586 CHARRANGE sel;
2587 GetSelection(sel); 2587 GetSelection(sel);
2588 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2588 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2589 } 2589 }
OLDNEW
« no previous file with comments | « chrome/browser/appcache/appcache_frontend_proxy.cc ('k') | chrome/browser/autocomplete/autocomplete_popup_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698