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 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2469 GetSelection(saved_sel); | 2469 GetSelection(saved_sel); |
2470 | 2470 |
2471 // See whether the contents are a URL with a non-empty host portion, which we | 2471 // See whether the contents are a URL with a non-empty host portion, which we |
2472 // should emphasize. To check for a URL, rather than using the type returned | 2472 // should emphasize. To check for a URL, rather than using the type returned |
2473 // by Parse(), ask the model, which will check the desired page transition for | 2473 // by Parse(), ask the model, which will check the desired page transition for |
2474 // this input. This can tell us whether an UNKNOWN input string is going to | 2474 // this input. This can tell us whether an UNKNOWN input string is going to |
2475 // be treated as a search or a navigation, and is the same method the Paste | 2475 // be treated as a search or a navigation, and is the same method the Paste |
2476 // And Go system uses. | 2476 // And Go system uses. |
2477 url_parse::Component scheme, host; | 2477 url_parse::Component scheme, host; |
2478 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host); | 2478 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host); |
2479 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); | 2479 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); |
Peter Kasting
2013/04/04 21:07:05
Nit: Remove this, it's unused
Patrick Riordan
2013/04/10 02:00:24
Done.
| |
2480 | 2480 |
2481 // Set the baseline emphasis. | 2481 // Set the baseline emphasis. |
2482 CHARFORMAT cf = {0}; | 2482 CHARFORMAT cf = {0}; |
2483 cf.dwMask = CFM_COLOR; | 2483 cf.dwMask = CFM_COLOR; |
2484 // If we're going to emphasize parts of the text, then the baseline state | 2484 // If we're going to emphasize parts of the text, then the baseline state |
2485 // should be "de-emphasized". If not, then everything should be rendered in | 2485 // should be "de-emphasized". If not, then everything should be rendered in |
2486 // the standard text color. | 2486 // the standard text color unless we should grey out the entire URL. |
2487 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2487 if (model()->CurrentTextIsURL() && |
Peter Kasting
2013/04/04 21:07:05
Nit: Slightly simpler:
bool grey_base = model()
Patrick Riordan
2013/04/10 02:00:24
Done.
| |
2488 security_level_, | 2488 (host.is_nonempty() || toolbar_model()->ShouldGreyOutURL())) { |
2489 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2489 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2490 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the | 2490 security_level_, LocationBarView::DEEMPHASIZED_TEXT)); |
2491 // format that will get applied to text added in the future, not to text | 2491 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets |
2492 // already in the edit. | 2492 // the format that will get applied to text added in the future, not to text |
2493 SelectAll(false); | 2493 // already in the edit. |
2494 SetSelectionCharFormat(cf); | 2494 SelectAll(false); |
2495 SetSelectionCharFormat(cf); | |
2495 | 2496 |
2496 if (emphasize) { | 2497 if (host.is_nonempty() && !toolbar_model()->ShouldGreyOutURL()) { |
2497 // We've found a host name, give it more emphasis. | 2498 // We've found a host name and we should provide emphasis to host names, |
2499 // so emphasize it. | |
2500 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | |
2501 security_level_, LocationBarView::TEXT)); | |
2502 SetSelection(host.begin, host.end()); | |
2503 SetSelectionCharFormat(cf); | |
2504 } | |
2505 } else { | |
2498 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2506 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2499 security_level_, LocationBarView::TEXT)); | 2507 security_level_, LocationBarView::TEXT)); |
2500 SetSelection(host.begin, host.end()); | 2508 // NOTE: Don't use SetDefaultCharFormat(). See above. |
2509 SelectAll(false); | |
2501 SetSelectionCharFormat(cf); | 2510 SetSelectionCharFormat(cf); |
2502 } | 2511 } |
2503 | 2512 |
2504 // Emphasize the scheme for security UI display purposes (if necessary). | 2513 // Emphasize the scheme for security UI display purposes (if necessary). |
2505 insecure_scheme_component_.reset(); | 2514 insecure_scheme_component_.reset(); |
2506 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 2515 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
2507 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | 2516 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { |
2508 if (security_level_ == ToolbarModel::SECURITY_ERROR) { | 2517 if (security_level_ == ToolbarModel::SECURITY_ERROR) { |
2509 insecure_scheme_component_.begin = scheme.begin; | 2518 insecure_scheme_component_.begin = scheme.begin; |
2510 insecure_scheme_component_.len = scheme.len; | 2519 insecure_scheme_component_.len = scheme.len; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2857 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2866 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2858 } | 2867 } |
2859 | 2868 |
2860 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2869 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2861 // Use font_.GetStringWidth() instead of | 2870 // Use font_.GetStringWidth() instead of |
2862 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2871 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2863 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2872 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2864 // PosFromChar(i) might return 0 when i is greater than 1. | 2873 // PosFromChar(i) might return 0 when i is greater than 1. |
2865 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2874 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2866 } | 2875 } |
OLD | NEW |