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 2406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2462 CHARRANGE saved_sel; | 2463 CHARRANGE saved_sel; |
2463 GetSelection(saved_sel); | 2464 GetSelection(saved_sel); |
2464 | 2465 |
2465 // See whether the contents are a URL with a non-empty host portion, which we | 2466 // See whether the contents are a URL with a non-empty host portion, which we |
2466 // should emphasize. To check for a URL, rather than using the type returned | 2467 // should emphasize. To check for a URL, rather than using the type returned |
2467 // by Parse(), ask the model, which will check the desired page transition for | 2468 // by Parse(), ask the model, which will check the desired page transition for |
2468 // this input. This can tell us whether an UNKNOWN input string is going to | 2469 // this input. This can tell us whether an UNKNOWN input string is going to |
2469 // be treated as a search or a navigation, and is the same method the Paste | 2470 // be treated as a search or a navigation, and is the same method the Paste |
2470 // And Go system uses. | 2471 // And Go system uses. |
2471 url_parse::Component scheme, host; | 2472 url_parse::Component scheme, host; |
2472 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host); | 2473 string16 text(GetText()); |
2473 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); | 2474 AutocompleteInput::ParseForEmphasizeComponents(text, &scheme, &host); |
2474 | 2475 |
2475 // Set the baseline emphasis. | 2476 // Set the baseline emphasis. |
2476 CHARFORMAT cf = {0}; | 2477 CHARFORMAT cf = {0}; |
2477 cf.dwMask = CFM_COLOR; | 2478 cf.dwMask = CFM_COLOR; |
2478 // If we're going to emphasize parts of the text, then the baseline state | 2479 // If we're going to emphasize parts of the text, then the baseline state |
2479 // should be "de-emphasized". If not, then everything should be rendered in | 2480 // should be "de-emphasized". If not, then everything should be rendered in |
2480 // the standard text color. | 2481 // the standard text color unless we should grey out the entire URL. |
| 2482 bool grey_out_url = text.substr(scheme.begin, scheme.len) == |
| 2483 UTF8ToUTF16(extensions::kExtensionScheme); |
| 2484 bool grey_base = model()->CurrentTextIsURL() && |
| 2485 (host.is_nonempty() || grey_out_url); |
2481 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2486 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2482 security_level_, | 2487 security_level_, |
2483 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2488 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
2484 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the | 2489 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets |
2485 // format that will get applied to text added in the future, not to text | 2490 // the format that will get applied to text added in the future, not to text |
2486 // already in the edit. | 2491 // already in the edit. |
2487 SelectAll(false); | 2492 SelectAll(false); |
2488 SetSelectionCharFormat(cf); | 2493 SetSelectionCharFormat(cf); |
2489 | 2494 if (host.is_nonempty() && !grey_out_url) { |
2490 if (emphasize) { | 2495 // We've found a host name and we should provide emphasis to host names, |
2491 // We've found a host name, give it more emphasis. | 2496 // so emphasize it. |
2492 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2497 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( |
2493 security_level_, LocationBarView::TEXT)); | 2498 security_level_, LocationBarView::TEXT)); |
2494 SetSelection(host.begin, host.end()); | 2499 SetSelection(host.begin, host.end()); |
2495 SetSelectionCharFormat(cf); | 2500 SetSelectionCharFormat(cf); |
2496 } | 2501 } |
2497 | 2502 |
2498 // Emphasize the scheme for security UI display purposes (if necessary). | 2503 // Emphasize the scheme for security UI display purposes (if necessary). |
2499 insecure_scheme_component_.reset(); | 2504 insecure_scheme_component_.reset(); |
2500 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 2505 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
2501 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | 2506 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2851 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2856 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2852 } | 2857 } |
2853 | 2858 |
2854 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2859 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2855 // Use font_.GetStringWidth() instead of | 2860 // Use font_.GetStringWidth() instead of |
2856 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2861 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2857 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2862 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2858 // PosFromChar(i) might return 0 when i is greater than 1. | 2863 // PosFromChar(i) might return 0 when i is greater than 1. |
2859 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2864 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2860 } | 2865 } |
OLD | NEW |