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