OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2456 // Save the selection. | 2456 // Save the selection. |
2457 CHARRANGE saved_sel; | 2457 CHARRANGE saved_sel; |
2458 GetSelection(saved_sel); | 2458 GetSelection(saved_sel); |
2459 | 2459 |
2460 // See whether the contents are a URL with a non-empty host portion, which we | 2460 // See whether the contents are a URL with a non-empty host portion, which we |
2461 // should emphasize. To check for a URL, rather than using the type returned | 2461 // should emphasize. To check for a URL, rather than using the type returned |
2462 // by Parse(), ask the model, which will check the desired page transition for | 2462 // by Parse(), ask the model, which will check the desired page transition for |
2463 // this input. This can tell us whether an UNKNOWN input string is going to | 2463 // this input. This can tell us whether an UNKNOWN input string is going to |
2464 // be treated as a search or a navigation, and is the same method the Paste | 2464 // be treated as a search or a navigation, and is the same method the Paste |
2465 // And Go system uses. | 2465 // And Go system uses. |
2466 url_parse::Component scheme, host; | 2466 url_parse::Component scheme; |
2467 url_parse::Component host; | |
Peter Kasting
2013/04/03 22:32:13
Nit: Again, don't split these
Patrick Riordan
2013/04/04 01:01:37
Done.
| |
2467 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host); | 2468 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host); |
2468 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); | 2469 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); |
2469 | 2470 |
2470 // Set the baseline emphasis. | 2471 // Set the baseline emphasis. |
2471 CHARFORMAT cf = {0}; | 2472 CHARFORMAT cf = {0}; |
2472 cf.dwMask = CFM_COLOR; | 2473 cf.dwMask = CFM_COLOR; |
2473 // If we're going to emphasize parts of the text, then the baseline state | 2474 // If we're going to emphasize parts of the text, then the baseline state |
2474 // should be "de-emphasized". If not, then everything should be rendered in | 2475 // should be "de-emphasized". If not, then everything should be rendered in |
2475 // the standard text color. | 2476 // the standard text color. If we should grey out the entire text then |
2477 // emphasize is set, but toolbar_model()->ShouldGreyOutURL() is also set. | |
2476 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2478 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2477 security_level_, | 2479 security_level_, |
2478 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2480 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
2479 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the | 2481 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the |
2480 // format that will get applied to text added in the future, not to text | 2482 // format that will get applied to text added in the future, not to text |
2481 // already in the edit. | 2483 // already in the edit. |
2482 SelectAll(false); | 2484 SelectAll(false); |
2483 SetSelectionCharFormat(cf); | 2485 SetSelectionCharFormat(cf); |
2484 | 2486 |
2485 if (emphasize) { | 2487 if (emphasize && !toolbar_model()->ShouldGreyOutURL()) { |
2486 // We've found a host name, give it more emphasis. | 2488 // We've found a host name and we should provide emphasis to host names, so |
2489 // emphasize it. | |
2487 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2490 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2488 security_level_, LocationBarView::TEXT)); | 2491 security_level_, LocationBarView::TEXT)); |
2489 SetSelection(host.begin, host.end()); | 2492 SetSelection(host.begin, host.end()); |
2490 SetSelectionCharFormat(cf); | 2493 SetSelectionCharFormat(cf); |
2491 } | 2494 } |
2492 | 2495 |
2493 // Emphasize the scheme for security UI display purposes (if necessary). | 2496 // Emphasize the scheme for security UI display purposes (if necessary). |
2494 insecure_scheme_component_.reset(); | 2497 insecure_scheme_component_.reset(); |
2495 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 2498 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
2496 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | 2499 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2846 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2849 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2847 } | 2850 } |
2848 | 2851 |
2849 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2852 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2850 // Use font_.GetStringWidth() instead of | 2853 // Use font_.GetStringWidth() instead of |
2851 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2854 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2852 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2855 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2853 // PosFromChar(i) might return 0 when i is greater than 1. | 2856 // PosFromChar(i) might return 0 when i is greater than 1. |
2854 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2857 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2855 } | 2858 } |
OLD | NEW |