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 25 matching lines...) Expand all Loading... | |
36 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 37 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
38 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 38 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
39 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 39 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
40 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 40 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
41 #include "chrome/browser/ui/views/missing_system_file_dialog_win.h" | 41 #include "chrome/browser/ui/views/missing_system_file_dialog_win.h" |
42 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 42 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
43 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
44 #include "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
45 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
46 #include "extensions/common/constants.h" | |
46 #include "googleurl/src/url_util.h" | 47 #include "googleurl/src/url_util.h" |
47 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
48 #include "net/base/escape.h" | 49 #include "net/base/escape.h" |
49 #include "skia/ext/skia_utils_win.h" | 50 #include "skia/ext/skia_utils_win.h" |
50 #include "ui/base/accessibility/accessible_view_state.h" | 51 #include "ui/base/accessibility/accessible_view_state.h" |
51 #include "ui/base/clipboard/clipboard.h" | 52 #include "ui/base/clipboard/clipboard.h" |
52 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 53 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
53 #include "ui/base/dragdrop/drag_drop_types.h" | 54 #include "ui/base/dragdrop/drag_drop_types.h" |
54 #include "ui/base/dragdrop/drag_source_win.h" | 55 #include "ui/base/dragdrop/drag_source_win.h" |
55 #include "ui/base/dragdrop/drop_target_win.h" | 56 #include "ui/base/dragdrop/drop_target_win.h" |
(...skipping 2410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2466 CHARRANGE saved_sel; | 2467 CHARRANGE saved_sel; |
2467 GetSelection(saved_sel); | 2468 GetSelection(saved_sel); |
2468 | 2469 |
2469 // See whether the contents are a URL with a non-empty host portion, which we | 2470 // See whether the contents are a URL with a non-empty host portion, which we |
2470 // should emphasize. To check for a URL, rather than using the type returned | 2471 // should emphasize. To check for a URL, rather than using the type returned |
2471 // by Parse(), ask the model, which will check the desired page transition for | 2472 // by Parse(), ask the model, which will check the desired page transition for |
2472 // this input. This can tell us whether an UNKNOWN input string is going to | 2473 // this input. This can tell us whether an UNKNOWN input string is going to |
2473 // be treated as a search or a navigation, and is the same method the Paste | 2474 // be treated as a search or a navigation, and is the same method the Paste |
2474 // And Go system uses. | 2475 // And Go system uses. |
2475 url_parse::Component scheme, host; | 2476 url_parse::Component scheme, host; |
2476 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host); | 2477 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host); |
Peter Kasting
2013/04/11 23:10:40
Pull this GetText() call out into a string16 temp
Patrick Riordan
2013/04/11 23:27:38
Done.
| |
2477 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); | |
2478 | 2478 |
2479 // Set the baseline emphasis. | 2479 // Set the baseline emphasis. |
2480 CHARFORMAT cf = {0}; | 2480 CHARFORMAT cf = {0}; |
2481 cf.dwMask = CFM_COLOR; | 2481 cf.dwMask = CFM_COLOR; |
2482 // If we're going to emphasize parts of the text, then the baseline state | 2482 // If we're going to emphasize parts of the text, then the baseline state |
2483 // should be "de-emphasized". If not, then everything should be rendered in | 2483 // should be "de-emphasized". If not, then everything should be rendered in |
2484 // the standard text color. | 2484 // the standard text color unless we should grey out the entire URL. |
2485 bool grey_out_url = GetText().substr(scheme.begin, scheme.len) == | |
2486 UTF8ToUTF16(extensions::kExtensionScheme); | |
2487 bool grey_base = model()->CurrentTextIsURL() && | |
2488 (host.is_nonempty() || grey_out_url); | |
2485 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2489 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2486 security_level_, | 2490 security_level_, |
2487 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2491 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
2488 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the | 2492 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets |
2489 // format that will get applied to text added in the future, not to text | 2493 // the format that will get applied to text added in the future, not to text |
2490 // already in the edit. | 2494 // already in the edit. |
2491 SelectAll(false); | 2495 SelectAll(false); |
2492 SetSelectionCharFormat(cf); | 2496 SetSelectionCharFormat(cf); |
2493 | 2497 if (host.is_nonempty() && !grey_out_url) { |
2494 if (emphasize) { | 2498 // We've found a host name and we should provide emphasis to host names, |
2495 // We've found a host name, give it more emphasis. | 2499 // so emphasize it. |
2496 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2500 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2497 security_level_, LocationBarView::TEXT)); | 2501 security_level_, LocationBarView::TEXT)); |
2498 SetSelection(host.begin, host.end()); | 2502 SetSelection(host.begin, host.end()); |
2499 SetSelectionCharFormat(cf); | 2503 SetSelectionCharFormat(cf); |
2500 } | 2504 } |
2501 | 2505 |
2502 // Emphasize the scheme for security UI display purposes (if necessary). | 2506 // Emphasize the scheme for security UI display purposes (if necessary). |
2503 insecure_scheme_component_.reset(); | 2507 insecure_scheme_component_.reset(); |
2504 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 2508 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
2505 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | 2509 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2855 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2859 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2856 } | 2860 } |
2857 | 2861 |
2858 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2862 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2859 // Use font_.GetStringWidth() instead of | 2863 // Use font_.GetStringWidth() instead of |
2860 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2864 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2861 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2865 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2862 // PosFromChar(i) might return 0 when i is greater than 1. | 2866 // PosFromChar(i) might return 0 when i is greater than 1. |
2863 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2867 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2864 } | 2868 } |
OLD | NEW |