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/cocoa/omnibox/omnibox_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/autocomplete/autocomplete_input.h" | 14 #include "chrome/browser/autocomplete/autocomplete_input.h" |
15 #include "chrome/browser/autocomplete/autocomplete_match.h" | 15 #include "chrome/browser/autocomplete/autocomplete_match.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/search/search.h" | |
17 #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 18 #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
18 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 19 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
19 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" | 20 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" |
20 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 21 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
21 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
22 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 23 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
24 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
26 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 // store existing state before anyone tries to setup the new | 198 // store existing state before anyone tries to setup the new |
198 // state. Anyhow, it would look something like this. | 199 // state. Anyhow, it would look something like this. |
199 #if 0 | 200 #if 0 |
200 [[field_ window] makeFirstResponder:field_]; | 201 [[field_ window] makeFirstResponder:field_]; |
201 [[field_ currentEditor] setSelectedRange:state->selection]; | 202 [[field_ currentEditor] setSelectedRange:state->selection]; |
202 #endif | 203 #endif |
203 } | 204 } |
204 } | 205 } |
205 | 206 |
206 void OmniboxViewMac::Update() { | 207 void OmniboxViewMac::Update() { |
208 if (chrome::ShouldDisplayOriginChip() || | |
Justin Donnelly
2014/02/14 14:57:14
Any reason not to check just for V2 here like you
groby-ooo-7-16
2014/02/15 01:28:14
That was based on Views, which does the same thing
| |
209 chrome::ShouldDisplayOriginChipV2()) { | |
210 [[field_ cell] setPlaceholderString: | |
211 base::SysUTF16ToNSString(GetHintText())]; | |
212 } | |
207 if (model()->UpdatePermanentText()) { | 213 if (model()->UpdatePermanentText()) { |
208 // Something visibly changed. Re-enable URL replacement. | 214 // Something visibly changed. Re-enable URL replacement. |
209 controller()->GetToolbarModel()->set_url_replacement_enabled(true); | 215 controller()->GetToolbarModel()->set_url_replacement_enabled(true); |
210 model()->UpdatePermanentText(); | 216 model()->UpdatePermanentText(); |
211 | 217 |
212 // Restore everything to the baseline look. | 218 // Restore everything to the baseline look. |
213 RevertAll(); | 219 RevertAll(); |
214 | 220 |
215 // TODO(shess): Figure out how this case is used, to make sure | 221 // TODO(shess): Figure out how this case is used, to make sure |
216 // we're getting the selection and popup right. | 222 // we're getting the selection and popup right. |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 } | 768 } |
763 } | 769 } |
764 } | 770 } |
765 | 771 |
766 return false; | 772 return false; |
767 } | 773 } |
768 | 774 |
769 void OmniboxViewMac::OnSetFocus(bool control_down) { | 775 void OmniboxViewMac::OnSetFocus(bool control_down) { |
770 model()->OnSetFocus(control_down); | 776 model()->OnSetFocus(control_down); |
771 controller()->OnSetFocus(); | 777 controller()->OnSetFocus(); |
778 | |
779 // TODO(groby): Not entirely correct, since the chip should only be disabled | |
780 // after mouseDown: was handled, to allow clicking on the origin chip. | |
781 if (chrome::ShouldDisplayOriginChipV2()) { | |
782 controller()->GetToolbarModel()->set_origin_chip_enabled(false); | |
783 controller()->OnChanged(); | |
784 } | |
772 } | 785 } |
773 | 786 |
774 void OmniboxViewMac::OnKillFocus() { | 787 void OmniboxViewMac::OnKillFocus() { |
775 // Tell the model to reset itself. | 788 // Tell the model to reset itself. |
776 model()->OnWillKillFocus(NULL); | 789 model()->OnWillKillFocus(NULL); |
777 model()->OnKillFocus(); | 790 model()->OnKillFocus(); |
791 | |
792 // If user input is not in progress, re-enable the origin chip and URL | |
793 // replacement. This addresses the case where the URL was shown by a call | |
794 // to ShowURL(). If the Omnibox acheived focus by other means, the calls to | |
Scott Hess - ex-Googler
2014/02/15 00:55:57
achieved.
groby-ooo-7-16
2014/02/15 01:28:14
Done.
| |
795 // set_url_replacement_enabled, UpdatePermanentText and RevertAll are not | |
796 // required (a call to OnChanged would be sufficient) but do no harm. | |
Scott Hess - ex-Googler
2014/02/15 00:55:57
My general take on things is that calls which scal
groby-ooo-7-16
2014/02/15 01:28:14
This is taken verbatim from Views, so there's cert
| |
797 if (chrome::ShouldDisplayOriginChipV2() && | |
798 !model()->user_input_in_progress()) { | |
799 controller()->GetToolbarModel()->set_origin_chip_enabled(true); | |
800 controller()->GetToolbarModel()->set_url_replacement_enabled(true); | |
801 model()->UpdatePermanentText(); | |
802 RevertAll(); | |
803 } | |
778 } | 804 } |
779 | 805 |
780 void OmniboxViewMac::OnMouseDown(NSInteger button_number) { | 806 void OmniboxViewMac::OnMouseDown(NSInteger button_number) { |
781 // Restore caret visibility whenever the user clicks in the the omnibox. This | 807 // Restore caret visibility whenever the user clicks in the the omnibox. This |
782 // is not always covered by OnSetFocus() because when clicking while the | 808 // is not always covered by OnSetFocus() because when clicking while the |
783 // omnibox has invisible focus does not trigger a new OnSetFocus() call. | 809 // omnibox has invisible focus does not trigger a new OnSetFocus() call. |
784 if (button_number == 0 || button_number == 1) | 810 if (button_number == 0 || button_number == 1) |
785 model()->SetCaretVisibility(true); | 811 model()->SetCaretVisibility(true); |
786 } | 812 } |
787 | 813 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 | 980 |
955 NSUInteger OmniboxViewMac::GetTextLength() const { | 981 NSUInteger OmniboxViewMac::GetTextLength() const { |
956 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 982 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
957 [[field_ stringValue] length]; | 983 [[field_ stringValue] length]; |
958 } | 984 } |
959 | 985 |
960 bool OmniboxViewMac::IsCaretAtEnd() const { | 986 bool OmniboxViewMac::IsCaretAtEnd() const { |
961 const NSRange selection = GetSelectedRange(); | 987 const NSRange selection = GetSelectedRange(); |
962 return NSMaxRange(selection) == GetTextLength(); | 988 return NSMaxRange(selection) == GetTextLength(); |
963 } | 989 } |
OLD | NEW |