OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2443 LineTo(hdc, clip_rect.left, clip_rect.bottom); | 2443 LineTo(hdc, clip_rect.left, clip_rect.bottom); |
2444 DeleteObject(SelectObject(hdc, last_pen)); | 2444 DeleteObject(SelectObject(hdc, last_pen)); |
2445 } | 2445 } |
2446 | 2446 |
2447 void OmniboxViewWin::TextChanged() { | 2447 void OmniboxViewWin::TextChanged() { |
2448 ScopedFreeze freeze(this, GetTextObjectModel()); | 2448 ScopedFreeze freeze(this, GetTextObjectModel()); |
2449 EmphasizeURLComponents(); | 2449 EmphasizeURLComponents(); |
2450 model_->OnChanged(); | 2450 model_->OnChanged(); |
2451 } | 2451 } |
2452 | 2452 |
2453 string16 OmniboxViewWin::GetClipboardText() const { | |
2454 // Try text format. | |
2455 ui::Clipboard* clipboard = g_browser_process->clipboard(); | |
2456 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), | |
2457 ui::Clipboard::BUFFER_STANDARD)) { | |
2458 string16 text; | |
2459 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text); | |
2460 // Note: Unlike in the find popup and textfield view, here we completely | |
2461 // remove whitespace strings containing newlines. We assume users are | |
2462 // most likely pasting in URLs that may have been split into multiple | |
2463 // lines in terminals, email programs, etc., and so linebreaks indicate | |
2464 // completely bogus whitespace that would just cause the input to be | |
2465 // invalid. | |
2466 return StripJavascriptSchemas(CollapseWhitespace(text, true)); | |
2467 } | |
2468 | |
2469 // Try bookmark format. | |
2470 // | |
2471 // It is tempting to try bookmark format first, but the URL we get out of a | |
2472 // bookmark has been cannonicalized via GURL. This means if a user copies | |
2473 // and pastes from the URL bar to itself, the text will get fixed up and | |
2474 // cannonicalized, which is not what the user expects. By pasting in this | |
2475 // order, we are sure to paste what the user copied. | |
2476 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), | |
2477 ui::Clipboard::BUFFER_STANDARD)) { | |
2478 std::string url_str; | |
2479 clipboard->ReadBookmark(NULL, &url_str); | |
2480 // pass resulting url string through GURL to normalize | |
2481 GURL url(url_str); | |
2482 if (url.is_valid()) | |
2483 return StripJavascriptSchemas(UTF8ToUTF16(url.spec())); | |
2484 } | |
2485 | |
2486 return string16(); | |
2487 } | |
2488 | |
2489 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const { | 2453 bool OmniboxViewWin::CanPasteAndGo(const string16& text) const { |
2490 return !popup_window_mode_ && model_->CanPasteAndGo(text); | 2454 return !popup_window_mode_ && model_->CanPasteAndGo(text); |
2491 } | 2455 } |
2492 | 2456 |
2493 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { | 2457 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { |
2494 if (!text_object_model_) { | 2458 if (!text_object_model_) { |
2495 // This is lazily initialized, instead of being initialized in the | 2459 // This is lazily initialized, instead of being initialized in the |
2496 // constructor, in order to avoid hurting startup performance. | 2460 // constructor, in order to avoid hurting startup performance. |
2497 base::win::ScopedComPtr<IRichEditOle, NULL> ole_interface; | 2461 base::win::ScopedComPtr<IRichEditOle, NULL> ole_interface; |
2498 ole_interface.Attach(GetOleInterface()); | 2462 ole_interface.Attach(GetOleInterface()); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2713 bool popup_window_mode, | 2677 bool popup_window_mode, |
2714 LocationBarView* location_bar) { | 2678 LocationBarView* location_bar) { |
2715 return new OmniboxViewWin(controller, | 2679 return new OmniboxViewWin(controller, |
2716 toolbar_model, | 2680 toolbar_model, |
2717 location_bar, | 2681 location_bar, |
2718 command_updater, | 2682 command_updater, |
2719 popup_window_mode, | 2683 popup_window_mode, |
2720 location_bar); | 2684 location_bar); |
2721 } | 2685 } |
2722 #endif | 2686 #endif |
OLD | NEW |