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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // twips are a unit of type measurement, and RichEdit controls use them | 455 // twips are a unit of type measurement, and RichEdit controls use them |
456 // to set offsets. | 456 // to set offsets. |
457 const int kTwipsPerInch = 1440; | 457 const int kTwipsPerInch = 1440; |
458 | 458 |
459 } // namespace | 459 } // namespace |
460 | 460 |
461 HMODULE OmniboxViewWin::loaded_library_module_ = NULL; | 461 HMODULE OmniboxViewWin::loaded_library_module_ = NULL; |
462 | 462 |
463 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, | 463 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, |
464 ToolbarModel* toolbar_model, | 464 ToolbarModel* toolbar_model, |
465 LocationBarView* parent_view, | 465 LocationBarView* location_bar, |
466 CommandUpdater* command_updater, | 466 CommandUpdater* command_updater, |
467 bool popup_window_mode, | 467 bool popup_window_mode, |
468 views::View* location_bar, | |
469 const gfx::Font& font, | 468 const gfx::Font& font, |
470 int font_y_offset) | 469 int font_y_offset) |
471 : OmniboxView(parent_view->profile(), controller, toolbar_model, | 470 : OmniboxView(location_bar->profile(), controller, toolbar_model, |
472 command_updater), | 471 command_updater), |
473 popup_view_( | 472 popup_view_( |
474 OmniboxPopupContentsView::Create(font, this, model(), location_bar)), | 473 OmniboxPopupContentsView::Create(font, this, model(), location_bar)), |
475 parent_view_(parent_view), | 474 location_bar_(location_bar), |
476 popup_window_mode_(popup_window_mode), | 475 popup_window_mode_(popup_window_mode), |
477 force_hidden_(false), | 476 force_hidden_(false), |
478 tracking_click_(), | 477 tracking_click_(), |
479 tracking_double_click_(false), | 478 tracking_double_click_(false), |
480 double_click_time_(0), | 479 double_click_time_(0), |
481 can_discard_mousemove_(false), | 480 can_discard_mousemove_(false), |
482 ignore_ime_messages_(false), | 481 ignore_ime_messages_(false), |
483 delete_at_end_pressed_(false), | 482 delete_at_end_pressed_(false), |
484 font_(font), | 483 font_(font), |
485 font_y_adjustment_(font_y_offset), | 484 font_y_adjustment_(font_y_offset), |
486 possible_drag_(false), | 485 possible_drag_(false), |
487 in_drag_(false), | 486 in_drag_(false), |
488 initiated_drag_(false), | 487 initiated_drag_(false), |
489 drop_highlight_position_(-1), | 488 drop_highlight_position_(-1), |
490 ime_candidate_window_open_(false), | 489 ime_candidate_window_open_(false), |
491 background_color_(skia::SkColorToCOLORREF(parent_view->GetColor( | 490 background_color_(skia::SkColorToCOLORREF(location_bar->GetColor( |
492 ToolbarModel::NONE, LocationBarView::BACKGROUND))), | 491 ToolbarModel::NONE, LocationBarView::BACKGROUND))), |
493 security_level_(ToolbarModel::NONE), | 492 security_level_(ToolbarModel::NONE), |
494 text_object_model_(NULL), | 493 text_object_model_(NULL), |
495 tsf_event_router_(base::win::IsTSFAwareRequired() ? | 494 tsf_event_router_(base::win::IsTSFAwareRequired() ? |
496 new ui::TSFEventRouter(this) : NULL) { | 495 new ui::TSFEventRouter(this) : NULL) { |
497 if (!loaded_library_module_) | 496 if (!loaded_library_module_) |
498 loaded_library_module_ = LoadLibrary(kRichEditDLLName); | 497 loaded_library_module_ = LoadLibrary(kRichEditDLLName); |
499 // RichEdit should be available; rare exceptions should use the Views omnibox. | 498 // RichEdit should be available; rare exceptions should use the Views omnibox. |
500 DCHECK(loaded_library_module_); | 499 DCHECK(loaded_library_module_); |
501 | 500 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 if (text_object_model_) | 575 if (text_object_model_) |
577 text_object_model_->Release(); | 576 text_object_model_->Release(); |
578 | 577 |
579 // We balance our reference count and unpatch when the last instance has | 578 // We balance our reference count and unpatch when the last instance has |
580 // been destroyed. This prevents us from relying on the AtExit or static | 579 // been destroyed. This prevents us from relying on the AtExit or static |
581 // destructor sequence to do our unpatching, which is generally fragile. | 580 // destructor sequence to do our unpatching, which is generally fragile. |
582 g_paint_patcher.Pointer()->DerefPatch(); | 581 g_paint_patcher.Pointer()->DerefPatch(); |
583 } | 582 } |
584 | 583 |
585 views::View* OmniboxViewWin::parent_view() const { | 584 views::View* OmniboxViewWin::parent_view() const { |
586 return parent_view_; | 585 return location_bar_; |
587 } | 586 } |
588 | 587 |
589 void OmniboxViewWin::SaveStateToTab(WebContents* tab) { | 588 void OmniboxViewWin::SaveStateToTab(WebContents* tab) { |
590 DCHECK(tab); | 589 DCHECK(tab); |
591 | 590 |
592 const OmniboxEditModel::State model_state(model()->GetStateForTabSwitch()); | 591 const OmniboxEditModel::State model_state(model()->GetStateForTabSwitch()); |
593 | 592 |
594 CHARRANGE selection; | 593 CHARRANGE selection; |
595 GetSelection(selection); | 594 GetSelection(selection); |
596 tab->SetUserData( | 595 tab->SetUserData( |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 // display area of IME windows, this workaround becomes unnecessary. | 1023 // display area of IME windows, this workaround becomes unnecessary. |
1025 HWND ime_window = ImmGetDefaultIMEWnd(edit_native_view); | 1024 HWND ime_window = ImmGetDefaultIMEWnd(edit_native_view); |
1026 return ime_window ? ime_window : HWND_NOTOPMOST; | 1025 return ime_window ? ime_window : HWND_NOTOPMOST; |
1027 } | 1026 } |
1028 | 1027 |
1029 gfx::NativeView OmniboxViewWin::GetRelativeWindowForPopup() const { | 1028 gfx::NativeView OmniboxViewWin::GetRelativeWindowForPopup() const { |
1030 return GetRelativeWindowForNativeView(GetNativeView()); | 1029 return GetRelativeWindowForNativeView(GetNativeView()); |
1031 } | 1030 } |
1032 | 1031 |
1033 void OmniboxViewWin::SetInstantSuggestion(const string16& suggestion) { | 1032 void OmniboxViewWin::SetInstantSuggestion(const string16& suggestion) { |
1034 parent_view_->SetInstantSuggestion(suggestion); | 1033 location_bar_->SetInstantSuggestion(suggestion); |
1035 } | 1034 } |
1036 | 1035 |
1037 int OmniboxViewWin::TextWidth() const { | 1036 int OmniboxViewWin::TextWidth() const { |
1038 return WidthNeededToDisplay(GetText()); | 1037 return WidthNeededToDisplay(GetText()); |
1039 } | 1038 } |
1040 | 1039 |
1041 string16 OmniboxViewWin::GetInstantSuggestion() const { | 1040 string16 OmniboxViewWin::GetInstantSuggestion() const { |
1042 return parent_view_->GetInstantSuggestion(); | 1041 return location_bar_->GetInstantSuggestion(); |
1043 } | 1042 } |
1044 | 1043 |
1045 bool OmniboxViewWin::IsImeComposing() const { | 1044 bool OmniboxViewWin::IsImeComposing() const { |
1046 if (tsf_event_router_) | 1045 if (tsf_event_router_) |
1047 return tsf_event_router_->IsImeComposing(); | 1046 return tsf_event_router_->IsImeComposing(); |
1048 bool ime_composing = false; | 1047 bool ime_composing = false; |
1049 HIMC context = ImmGetContext(m_hWnd); | 1048 HIMC context = ImmGetContext(m_hWnd); |
1050 if (context) { | 1049 if (context) { |
1051 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); | 1050 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); |
1052 ImmReleaseContext(m_hWnd, context); | 1051 ImmReleaseContext(m_hWnd, context); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 return command_updater()->IsCommandEnabled(command_id); | 1199 return command_updater()->IsCommandEnabled(command_id); |
1201 default: | 1200 default: |
1202 NOTREACHED(); | 1201 NOTREACHED(); |
1203 return false; | 1202 return false; |
1204 } | 1203 } |
1205 } | 1204 } |
1206 | 1205 |
1207 bool OmniboxViewWin::GetAcceleratorForCommandId( | 1206 bool OmniboxViewWin::GetAcceleratorForCommandId( |
1208 int command_id, | 1207 int command_id, |
1209 ui::Accelerator* accelerator) { | 1208 ui::Accelerator* accelerator) { |
1210 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator); | 1209 return location_bar_->GetWidget()->GetAccelerator(command_id, accelerator); |
1211 } | 1210 } |
1212 | 1211 |
1213 bool OmniboxViewWin::IsItemForCommandIdDynamic(int command_id) const { | 1212 bool OmniboxViewWin::IsItemForCommandIdDynamic(int command_id) const { |
1214 // No need to change the default IDS_PASTE_AND_GO label unless this is a | 1213 // No need to change the default IDS_PASTE_AND_GO label unless this is a |
1215 // search. | 1214 // search. |
1216 return command_id == IDS_PASTE_AND_GO; | 1215 return command_id == IDS_PASTE_AND_GO; |
1217 } | 1216 } |
1218 | 1217 |
1219 string16 OmniboxViewWin::GetLabelForCommandId(int command_id) const { | 1218 string16 OmniboxViewWin::GetLabelForCommandId(int command_id) const { |
1220 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); | 1219 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 SetMsgHandled(false); | 2015 SetMsgHandled(false); |
2017 } | 2016 } |
2018 | 2017 |
2019 void OmniboxViewWin::OnRButtonUp(UINT /*keys*/, const CPoint& point) { | 2018 void OmniboxViewWin::OnRButtonUp(UINT /*keys*/, const CPoint& point) { |
2020 SelectAllIfNecessary(kRight, point); | 2019 SelectAllIfNecessary(kRight, point); |
2021 tracking_click_[kRight] = false; | 2020 tracking_click_[kRight] = false; |
2022 SetMsgHandled(false); | 2021 SetMsgHandled(false); |
2023 } | 2022 } |
2024 | 2023 |
2025 void OmniboxViewWin::OnSetFocus(HWND focus_wnd) { | 2024 void OmniboxViewWin::OnSetFocus(HWND focus_wnd) { |
2026 views::FocusManager* focus_manager = parent_view_->GetFocusManager(); | 2025 views::FocusManager* focus_manager = location_bar_->GetFocusManager(); |
2027 if (focus_manager) { | 2026 if (focus_manager) { |
2028 // Notify the FocusManager that the focused view is now the location bar | 2027 // Notify the FocusManager that the focused view is now the location bar |
2029 // (our parent view). | 2028 // (our parent view). |
2030 focus_manager->SetFocusedView(parent_view_); | 2029 focus_manager->SetFocusedView(location_bar_); |
2031 } else { | 2030 } else { |
2032 NOTREACHED(); | 2031 NOTREACHED(); |
2033 } | 2032 } |
2034 | 2033 |
2035 model()->OnSetFocus(GetKeyState(VK_CONTROL) < 0); | 2034 model()->OnSetFocus(GetKeyState(VK_CONTROL) < 0); |
2036 | 2035 |
2037 // Restore saved selection if available. | 2036 // Restore saved selection if available. |
2038 if (saved_selection_for_focus_change_.cpMin != -1) { | 2037 if (saved_selection_for_focus_change_.cpMin != -1) { |
2039 SetSelectionRange(saved_selection_for_focus_change_); | 2038 SetSelectionRange(saved_selection_for_focus_change_); |
2040 saved_selection_for_focus_change_.cpMin = -1; | 2039 saved_selection_for_focus_change_.cpMin = -1; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2456 // Set the baseline emphasis. | 2455 // Set the baseline emphasis. |
2457 CHARFORMAT cf = {0}; | 2456 CHARFORMAT cf = {0}; |
2458 cf.dwMask = CFM_COLOR; | 2457 cf.dwMask = CFM_COLOR; |
2459 // If we're going to emphasize parts of the text, then the baseline state | 2458 // If we're going to emphasize parts of the text, then the baseline state |
2460 // should be "de-emphasized". If not, then everything should be rendered in | 2459 // should be "de-emphasized". If not, then everything should be rendered in |
2461 // the standard text color unless we should grey out the entire URL. | 2460 // the standard text color unless we should grey out the entire URL. |
2462 bool grey_out_url = text.substr(scheme.begin, scheme.len) == | 2461 bool grey_out_url = text.substr(scheme.begin, scheme.len) == |
2463 UTF8ToUTF16(extensions::kExtensionScheme); | 2462 UTF8ToUTF16(extensions::kExtensionScheme); |
2464 bool grey_base = model()->CurrentTextIsURL() && | 2463 bool grey_base = model()->CurrentTextIsURL() && |
2465 (host.is_nonempty() || grey_out_url); | 2464 (host.is_nonempty() || grey_out_url); |
2466 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2465 cf.crTextColor = skia::SkColorToCOLORREF(location_bar_->GetColor( |
2467 security_level_, | 2466 security_level_, |
2468 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2467 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
2469 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets | 2468 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets |
2470 // the format that will get applied to text added in the future, not to text | 2469 // the format that will get applied to text added in the future, not to text |
2471 // already in the edit. | 2470 // already in the edit. |
2472 SelectAll(false); | 2471 SelectAll(false); |
2473 SetSelectionCharFormat(cf); | 2472 SetSelectionCharFormat(cf); |
2474 if (host.is_nonempty() && !grey_out_url) { | 2473 if (host.is_nonempty() && !grey_out_url) { |
2475 // We've found a host name and we should provide emphasis to host names, | 2474 // We've found a host name and we should provide emphasis to host names, |
2476 // so emphasize it. | 2475 // so emphasize it. |
2477 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2476 cf.crTextColor = skia::SkColorToCOLORREF(location_bar_->GetColor( |
2478 security_level_, LocationBarView::TEXT)); | 2477 security_level_, LocationBarView::TEXT)); |
2479 SetSelection(host.begin, host.end()); | 2478 SetSelection(host.begin, host.end()); |
2480 SetSelectionCharFormat(cf); | 2479 SetSelectionCharFormat(cf); |
2481 } | 2480 } |
2482 | 2481 |
2483 // Emphasize the scheme for security UI display purposes (if necessary). | 2482 // Emphasize the scheme for security UI display purposes (if necessary). |
2484 insecure_scheme_component_.reset(); | 2483 insecure_scheme_component_.reset(); |
2485 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 2484 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
2486 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | 2485 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { |
2487 if (security_level_ == ToolbarModel::SECURITY_ERROR) { | 2486 if (security_level_ == ToolbarModel::SECURITY_ERROR) { |
2488 insecure_scheme_component_.begin = scheme.begin; | 2487 insecure_scheme_component_.begin = scheme.begin; |
2489 insecure_scheme_component_.len = scheme.len; | 2488 insecure_scheme_component_.len = scheme.len; |
2490 } | 2489 } |
2491 cf.crTextColor = skia::SkColorToCOLORREF(parent_view_->GetColor( | 2490 cf.crTextColor = skia::SkColorToCOLORREF(location_bar_->GetColor( |
2492 security_level_, LocationBarView::SECURITY_TEXT)); | 2491 security_level_, LocationBarView::SECURITY_TEXT)); |
2493 SetSelection(scheme.begin, scheme.end()); | 2492 SetSelection(scheme.begin, scheme.end()); |
2494 SetSelectionCharFormat(cf); | 2493 SetSelectionCharFormat(cf); |
2495 } | 2494 } |
2496 | 2495 |
2497 // Restore the selection. | 2496 // Restore the selection. |
2498 SetSelectionRange(saved_sel); | 2497 SetSelectionRange(saved_sel); |
2499 } | 2498 } |
2500 | 2499 |
2501 void OmniboxViewWin::EraseTopOfSelection(CDC* dc, | 2500 void OmniboxViewWin::EraseTopOfSelection(CDC* dc, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2578 const SkRect selection_rect = { | 2577 const SkRect selection_rect = { |
2579 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), | 2578 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), |
2580 SkIntToScalar(0), | 2579 SkIntToScalar(0), |
2581 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), | 2580 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), |
2582 SkIntToScalar(scheme_rect.Height()) }; | 2581 SkIntToScalar(scheme_rect.Height()) }; |
2583 | 2582 |
2584 // Draw the unselected portion of the stroke. | 2583 // Draw the unselected portion of the stroke. |
2585 sk_canvas->save(); | 2584 sk_canvas->save(); |
2586 if (selection_rect.isEmpty() || | 2585 if (selection_rect.isEmpty() || |
2587 sk_canvas->clipRect(selection_rect, SkRegion::kDifference_Op)) { | 2586 sk_canvas->clipRect(selection_rect, SkRegion::kDifference_Op)) { |
2588 paint.setColor(parent_view_->GetColor(security_level_, | 2587 paint.setColor(location_bar_->GetColor(security_level_, |
2589 LocationBarView::SECURITY_TEXT)); | 2588 LocationBarView::SECURITY_TEXT)); |
2590 sk_canvas->drawLine(start_point.fX, start_point.fY, | 2589 sk_canvas->drawLine(start_point.fX, start_point.fY, |
2591 end_point.fX, end_point.fY, paint); | 2590 end_point.fX, end_point.fY, paint); |
2592 } | 2591 } |
2593 sk_canvas->restore(); | 2592 sk_canvas->restore(); |
2594 | 2593 |
2595 // Draw the selected portion of the stroke. | 2594 // Draw the selected portion of the stroke. |
2596 if (!selection_rect.isEmpty() && sk_canvas->clipRect(selection_rect)) { | 2595 if (!selection_rect.isEmpty() && sk_canvas->clipRect(selection_rect)) { |
2597 paint.setColor(parent_view_->GetColor(security_level_, | 2596 paint.setColor(location_bar_->GetColor(security_level_, |
2598 LocationBarView::SELECTED_TEXT)); | 2597 LocationBarView::SELECTED_TEXT)); |
2599 sk_canvas->drawLine(start_point.fX, start_point.fY, | 2598 sk_canvas->drawLine(start_point.fX, start_point.fY, |
2600 end_point.fX, end_point.fY, paint); | 2599 end_point.fX, end_point.fY, paint); |
2601 } | 2600 } |
2602 | 2601 |
2603 // Now copy what we drew to the target HDC. | 2602 // Now copy what we drew to the target HDC. |
2604 skia::DrawToNativeContext(sk_canvas, hdc, | 2603 skia::DrawToNativeContext(sk_canvas, hdc, |
2605 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, | 2604 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, |
2606 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - | 2605 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - |
2607 canvas_clip_rect.top, &canvas_paint_clip_rect); | 2606 canvas_clip_rect.top, &canvas_paint_clip_rect); |
2608 } | 2607 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2836 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2835 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2837 } | 2836 } |
2838 | 2837 |
2839 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2838 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2840 // Use font_.GetStringWidth() instead of PosFromChar(GetTextLength()) because | 2839 // Use font_.GetStringWidth() instead of PosFromChar(GetTextLength()) because |
2841 // PosFromChar() is apparently buggy. In both LTR UI and RTL UI with | 2840 // PosFromChar() is apparently buggy. In both LTR UI and RTL UI with |
2842 // left-to-right layout, PosFromChar(i) might return 0 when i is greater than | 2841 // left-to-right layout, PosFromChar(i) might return 0 when i is greater than |
2843 // 1. | 2842 // 1. |
2844 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2843 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2845 } | 2844 } |
OLD | NEW |