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

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

Issue 8417004: OmniboxView: Attempt to fix a crash in GetSelectedText(). (Closed) Base URL: svn://svn.chromium.org/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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 string16 str; 614 string16 str;
615 GetWindowText(WriteInto(&str, len), len); 615 GetWindowText(WriteInto(&str, len), len);
Peter Kasting 2011/10/27 18:17:53 Can you also put this line under the condition:
James Hawkins 2011/10/27 18:26:42 Done. I structured it similar to the other change
616 return str; 616 return str;
617 } 617 }
618 618
619 bool OmniboxViewWin::IsEditingOrEmpty() const { 619 bool OmniboxViewWin::IsEditingOrEmpty() const {
620 return model_->user_input_in_progress() || (GetTextLength() == 0); 620 return model_->user_input_in_progress() || (GetTextLength() == 0);
621 } 621 }
622 622
623 int OmniboxViewWin::GetIcon() const { 623 int OmniboxViewWin::GetIcon() const {
624 return IsEditingOrEmpty() ? 624 return IsEditingOrEmpty() ?
625 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : 625 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 long flags; 2102 long flags;
2103 selection->GetFlags(&flags); 2103 selection->GetFlags(&flags);
2104 if (flags & tomSelStartActive) 2104 if (flags & tomSelStartActive)
2105 std::swap(sel.cpMin, sel.cpMax); 2105 std::swap(sel.cpMin, sel.cpMax);
2106 } 2106 }
2107 2107
2108 string16 OmniboxViewWin::GetSelectedText() const { 2108 string16 OmniboxViewWin::GetSelectedText() const {
2109 // Figure out the length of the selection. 2109 // Figure out the length of the selection.
2110 CHARRANGE sel; 2110 CHARRANGE sel;
2111 GetSel(sel); 2111 GetSel(sel);
2112 if (sel.cpMin == sel.cpMax)
2113 return string16();
Peter Kasting 2011/10/27 18:17:53 Nit: Might want to add an EOL comment: "// GetSelT
James Hawkins 2011/10/27 18:26:42 Done.
2112 2114
2113 // Grab the selected text. 2115 // Grab the selected text.
2114 string16 str; 2116 string16 str;
2115 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); 2117 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1));
2116 return str; 2118 return str;
2117 } 2119 }
2118 2120
2119 void OmniboxViewWin::SetSelection(LONG start, LONG end) { 2121 void OmniboxViewWin::SetSelection(LONG start, LONG end) {
2120 SetSel(start, end); 2122 SetSel(start, end);
2121 2123
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 // PosFromChar(i) might return 0 when i is greater than 1. 2640 // PosFromChar(i) might return 0 when i is greater than 1.
2639 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2641 return font_.GetStringWidth(text) + GetHorizontalMargin();
2640 } 2642 }
2641 2643
2642 bool OmniboxViewWin::IsCaretAtEnd() const { 2644 bool OmniboxViewWin::IsCaretAtEnd() const {
2643 long length = GetTextLength(); 2645 long length = GetTextLength();
2644 CHARRANGE sel; 2646 CHARRANGE sel;
2645 GetSelection(sel); 2647 GetSelection(sel);
2646 return sel.cpMin == sel.cpMax && sel.cpMin == length; 2648 return sel.cpMin == sel.cpMax && sel.cpMin == length;
2647 } 2649 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698