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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_win.cc

Issue 8418034: Make string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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/ui/views/omnibox/omnibox_view_win.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 // synchronously change the permanent text to the new URL. If we don't freeze 604 // synchronously change the permanent text to the new URL. If we don't freeze
605 // here, the user could potentially see a flicker of the current URL before 605 // here, the user could potentially see a flicker of the current URL before
606 // the new one reappears, which would look glitchy. 606 // the new one reappears, which would look glitchy.
607 ScopedFreeze freeze(this, GetTextObjectModel()); 607 ScopedFreeze freeze(this, GetTextObjectModel());
608 model_->OpenMatch(match, disposition, alternate_nav_url, 608 model_->OpenMatch(match, disposition, alternate_nav_url,
609 selected_line, keyword); 609 selected_line, keyword);
610 } 610 }
611 611
612 string16 OmniboxViewWin::GetText() const { 612 string16 OmniboxViewWin::GetText() const {
613 const int len = GetTextLength() + 1; 613 const int len = GetTextLength() + 1;
614 if (len <= 1)
615 return string16();
616
617 string16 str; 614 string16 str;
618 GetWindowText(WriteInto(&str, len), len); 615 if (len > 1)
616 GetWindowText(WriteInto(&str, len), len);
619 return str; 617 return str;
620 } 618 }
621 619
622 bool OmniboxViewWin::IsEditingOrEmpty() const { 620 bool OmniboxViewWin::IsEditingOrEmpty() const {
623 return model_->user_input_in_progress() || (GetTextLength() == 0); 621 return model_->user_input_in_progress() || (GetTextLength() == 0);
624 } 622 }
625 623
626 int OmniboxViewWin::GetIcon() const { 624 int OmniboxViewWin::GetIcon() const {
627 return IsEditingOrEmpty() ? 625 return IsEditingOrEmpty() ?
628 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : 626 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 base::win::ScopedComPtr<ITextSelection> selection; 2100 base::win::ScopedComPtr<ITextSelection> selection;
2103 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); 2101 const HRESULT hr = text_object_model->GetSelection(selection.Receive());
2104 DCHECK_EQ(S_OK, hr); 2102 DCHECK_EQ(S_OK, hr);
2105 long flags; 2103 long flags;
2106 selection->GetFlags(&flags); 2104 selection->GetFlags(&flags);
2107 if (flags & tomSelStartActive) 2105 if (flags & tomSelStartActive)
2108 std::swap(sel.cpMin, sel.cpMax); 2106 std::swap(sel.cpMin, sel.cpMax);
2109 } 2107 }
2110 2108
2111 string16 OmniboxViewWin::GetSelectedText() const { 2109 string16 OmniboxViewWin::GetSelectedText() const {
2112 // Figure out the length of the selection.
2113 CHARRANGE sel; 2110 CHARRANGE sel;
2114 GetSel(sel); 2111 GetSel(sel);
2115 if (sel.cpMin == sel.cpMax) // GetSelText() crashes on NULL input.
2116 return string16();
2117
2118 // Grab the selected text.
2119 string16 str; 2112 string16 str;
2120 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); 2113 if (sel.cpMin != sel.cpMax)
2114 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1));
2121 return str; 2115 return str;
2122 } 2116 }
2123 2117
2124 void OmniboxViewWin::SetSelection(LONG start, LONG end) { 2118 void OmniboxViewWin::SetSelection(LONG start, LONG end) {
2125 SetSel(start, end); 2119 SetSel(start, end);
2126 2120
2127 if (start <= end) 2121 if (start <= end)
2128 return; 2122 return;
2129 2123
2130 // We need to reverse the direction of the selection. 2124 // We need to reverse the direction of the selection.
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
2643 // PosFromChar(i) might return 0 when i is greater than 1. 2637 // PosFromChar(i) might return 0 when i is greater than 1.
2644 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2638 return font_.GetStringWidth(text) + GetHorizontalMargin();
2645 } 2639 }
2646 2640
2647 bool OmniboxViewWin::IsCaretAtEnd() const { 2641 bool OmniboxViewWin::IsCaretAtEnd() const {
2648 long length = GetTextLength(); 2642 long length = GetTextLength();
2649 CHARRANGE sel; 2643 CHARRANGE sel;
2650 GetSelection(sel); 2644 GetSelection(sel);
2651 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2645 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2652 } 2646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698