#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
+#include "chrome/browser/ui/views/settings_api_bubble_helper_views.h"
+#include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/constants.h"
#include "grit/ui_strings.h"
#include "net/base/escape.h"
#include "third_party/skia/include/core/SkColor.h"
-#include "ui/base/accessibility/accessible_view_state.h"
+#include "ui/accessibility/ax_view_state.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/event.h"
+#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/selection_model.h"
#if defined(USE_AURA)
#include "ui/aura/client/focus_client.h"
-#include "ui/aura/root_window.h"
+#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
#endif
if (popup_window_mode_)
SetReadOnly(true);
- if (chrome::ShouldDisplayOriginChip())
- set_placeholder_text(l10n_util::GetStringUTF16(IDS_OMNIBOX_EMPTY_HINT));
-
// Initialize the popup view using the same font.
popup_view_.reset(OmniboxPopupContentsView::Create(
GetFontList(), this, model(), location_bar_view_));
chromeos::input_method::InputMethodManager::Get()->
AddCandidateWindowObserver(this);
#endif
+
+ fade_in_animation_.reset(new gfx::SlideAnimation(this));
+ fade_in_animation_->SetTweenType(gfx::Tween::LINEAR);
+ fade_in_animation_->SetSlideDuration(300);
+}
+
+void OmniboxViewViews::FadeIn() {
+ fade_in_animation_->Show();
}
////////////////////////////////////////////////////////////////////////////////
return kViewClassName;
}
-void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {
- if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) {
- select_all_on_gesture_tap_ = true;
-
- // If we're trying to select all on tap, invalidate any saved selection lest
- // restoring it fights with the "select all" action.
- saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
- }
-
- if (select_all_on_gesture_tap_ && event->type() == ui::ET_GESTURE_TAP)
- SelectAll(false);
-
- if (event->type() == ui::ET_GESTURE_TAP ||
- event->type() == ui::ET_GESTURE_TAP_CANCEL ||
- event->type() == ui::ET_GESTURE_TWO_FINGER_TAP ||
- event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
- event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
- event->type() == ui::ET_GESTURE_LONG_PRESS ||
- event->type() == ui::ET_GESTURE_LONG_TAP) {
- select_all_on_gesture_tap_ = false;
+void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) {
+ if (fade_in_animation_->is_animating()) {
+ canvas->SaveLayerAlpha(static_cast<uint8>(
+ fade_in_animation_->CurrentValueBetween(0, 255)));
+ views::Textfield::OnPaint(canvas);
+ canvas->Restore();
+ } else {
+ views::Textfield::OnPaint(canvas);
}
-
- views::Textfield::OnGestureEvent(event);
-}
-
-void OmniboxViewViews::GetAccessibleState(ui::AccessibleViewState* state) {
- location_bar_view_->GetAccessibleState(state);
- state->role = ui::AccessibilityTypes::ROLE_TEXT;
}
bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
}
bool OmniboxViewViews::OnMouseDragged(const ui::MouseEvent& event) {
- select_all_on_mouse_release_ = false;
+ if (ExceededDragThreshold(event.location() - last_click_location()))
+ select_all_on_mouse_release_ = false;
return views::Textfield::OnMouseDragged(event);
}
void OmniboxViewViews::OnMouseReleased(const ui::MouseEvent& event) {
views::Textfield::OnMouseReleased(event);
- // When the user has clicked and released to give us focus, select all unless
- // we're omitting the URL (in which case refining an existing query is common
- // enough that we do click-to-place-cursor).
- if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
- select_all_on_mouse_release_ &&
- !controller()->GetToolbarModel()->WouldReplaceURL()) {
- // Select all in the reverse direction so as not to scroll the caret
- // into view and shift the contents jarringly.
- SelectAll(true);
+ if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) {
+ // When the user has clicked and released to give us focus, select all
+ // unless we're omitting the URL (in which case refining an existing query
+ // is common enough that we do click-to-place-cursor).
+ if (select_all_on_mouse_release_ &&
+ !controller()->GetToolbarModel()->WouldReplaceURL()) {
+ // Select all in the reverse direction so as not to scroll the caret
+ // into view and shift the contents jarringly.
+ SelectAll(true);
+ }
+
+ HandleOriginChipMouseRelease();
}
select_all_on_mouse_release_ = false;
}
return views::Textfield::OnKeyReleased(event);
}
+void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {
+ if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) {
+ select_all_on_gesture_tap_ = true;
+
+ // If we're trying to select all on tap, invalidate any saved selection lest
+ // restoring it fights with the "select all" action.
+ saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
+ }
+
+ if (select_all_on_gesture_tap_ && event->type() == ui::ET_GESTURE_TAP)
+ SelectAll(false);
+
+ if (event->type() == ui::ET_GESTURE_TAP ||
+ event->type() == ui::ET_GESTURE_TAP_CANCEL ||
+ event->type() == ui::ET_GESTURE_TWO_FINGER_TAP ||
+ event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
+ event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
+ event->type() == ui::ET_GESTURE_LONG_PRESS ||
+ event->type() == ui::ET_GESTURE_LONG_TAP) {
+ select_all_on_gesture_tap_ = false;
+ }
+
+ views::Textfield::OnGestureEvent(event);
+}
+
+void OmniboxViewViews::AboutToRequestFocusFromTabTraversal(bool reverse) {
+ // Tabbing into the omnibox should affect the origin chip in the same way
+ // clicking it should.
+ HandleOriginChipMouseRelease();
+}
+
bool OmniboxViewViews::SkipDefaultKeyEventProcessing(
const ui::KeyEvent& event) {
if (views::FocusManager::IsTabTraversalKeyEvent(event) &&
return Textfield::SkipDefaultKeyEventProcessing(event);
}
+void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) {
+ location_bar_view_->GetAccessibleState(state);
+ state->role = ui::AX_ROLE_TEXT_FIELD;
+}
+
bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {
// This must run before acclerator handling invokes a focus change on tab.
// Note the parallel with SkipDefaultKeyEventProcessing above.
// Tell the model to reset itself.
model()->OnKillFocus();
+ // Ignore loss of focus if we lost focus because the website settings popup
+ // is open. When the popup is destroyed, focus will return to the Omnibox.
+ if (!WebsiteSettingsPopupView::IsPopupShowing())
+ OnDidKillFocus();
+
// Make sure the beginning of the text is visible.
SelectRange(gfx::Range(0));
}
+base::string16 OmniboxViewViews::GetSelectionClipboardText() const {
+ return SanitizeTextForPaste(Textfield::GetSelectionClipboardText());
+}
+
////////////////////////////////////////////////////////////////////////////////
// OmniboxViewViews, OmniboxView implementation:
}
void OmniboxViewViews::Update() {
+ if (chrome::ShouldDisplayOriginChip() || chrome::ShouldDisplayOriginChipV2())
+ set_placeholder_text(GetHintText());
+
const ToolbarModel::SecurityLevel old_security_level = security_level_;
security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false);
if (model()->UpdatePermanentText()) {
controller()->GetToolbarModel()->set_url_replacement_enabled(true);
model()->UpdatePermanentText();
- // Tweak: if the user had all the text selected, select all the new text.
+ // Select all the new text if the user had all the old text selected, or if
+ // there was no previous text (for new tab page URL replacement extensions).
// This makes one particular case better: the user clicks in the box to
// change it right before the permanent URL is changed. Since the new URL
// is still fully selected, the user's typing will replace the edit contents
// as they'd intended.
- const gfx::Range range(GetSelectedRange());
- const bool was_select_all = (range.length() == text().length());
+ const bool was_select_all = IsSelectAll();
+ const bool was_reversed = GetSelectedRange().is_reversed();
RevertAll();
// and address cases like this, but it seems better to just not muck with
// things when the omnibox isn't focused to begin with.
if (was_select_all && model()->has_focus())
- SelectAll(range.is_reversed());
+ SelectAll(was_reversed);
} else if (old_security_level != security_level_) {
EmphasizeURLComponents();
}
GetInputMethod()->ShowImeIfNeeded();
}
+void OmniboxViewViews::OnMatchOpened(const AutocompleteMatch& match,
+ Profile* profile,
+ content::WebContents* web_contents) const {
+ extensions::MaybeShowExtensionControlledSearchNotification(
+ profile, web_contents, match);
+}
+
bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
if (command_id == IDS_APP_PASTE)
return !read_only() && !GetClipboardText().empty();
return !read_only() && model()->CanPasteAndGo(GetClipboardText());
if (command_id == IDS_SHOW_URL)
return controller()->GetToolbarModel()->WouldReplaceURL();
- return Textfield::IsCommandIdEnabled(command_id) ||
+ return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP ||
+ Textfield::IsCommandIdEnabled(command_id) ||
command_updater()->IsCommandEnabled(command_id);
}
model()->PasteAndGo(GetClipboardText());
break;
case IDS_SHOW_URL:
- ShowURL();
+ controller()->ShowURL();
break;
case IDC_EDIT_SEARCH_ENGINES:
command_updater()->ExecuteCommand(command_id);
break;
+ case IDS_MOVE_DOWN:
+ case IDS_MOVE_UP:
+ model()->OnUpOrDownKeyPressed(command_id == IDS_MOVE_DOWN ? 1 : -1);
+ break;
default:
OnBeforePossibleChange();
}
////////////////////////////////////////////////////////////////////////////////
+// OmniboxViewViews, gfx::AnimationDelegate implementation:
+
+void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) {
+ SchedulePaint();
+}
+
+void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) {
+ fade_in_animation_->Reset();
+}
+
+////////////////////////////////////////////////////////////////////////////////
// OmniboxViewViews, views::TextfieldController implementation:
void OmniboxViewViews::ContentsChanged(views::Textfield* sender,
OnAfterPossibleChange();
}
-void OmniboxViewViews::OnAfterCutOrCopy() {
+void OmniboxViewViews::OnAfterCutOrCopy(ui::ClipboardType clipboard_type) {
ui::Clipboard* cb = ui::Clipboard::GetForCurrentThread();
base::string16 selected_text;
- cb->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &selected_text);
+ cb->ReadText(clipboard_type, &selected_text);
GURL url;
bool write_url;
model()->AdjustTextForCopy(GetSelectedRange().GetMin(), IsSelectAll(),
if (write_url) {
BookmarkNodeData data;
data.ReadFromTuple(url, selected_text);
- data.WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE);
+ data.WriteToClipboard(clipboard_type);
} else {
ui::ScopedClipboardWriter scoped_clipboard_writer(
- ui::Clipboard::GetForCurrentThread(), ui::CLIPBOARD_TYPE_COPY_PASTE);
+ ui::Clipboard::GetForCurrentThread(), clipboard_type);
scoped_clipboard_writer.WriteText(selected_text);
}
}
}
void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) {
- base::string16 selected_text = GetSelectedText();
GURL url;
bool write_url;
bool is_all_selected = IsSelectAll();
+ base::string16 selected_text = GetSelectedText();
model()->AdjustTextForCopy(GetSelectedRange().GetMin(), is_all_selected,
&selected_text, &url, &write_url);
data->SetString(selected_text);
if (HasTextBeingDragged())
return ui::DragDropTypes::DRAG_NONE;
- if (data.HasURL()) {
+ if (data.HasURL(ui::OSExchangeData::CONVERT_FILENAMES)) {
GURL url;
base::string16 title;
if (data.GetURLAndTitle(
} else if (data.HasString()) {
base::string16 text;
if (data.GetString(&text)) {
- base::string16 collapsed_text(CollapseWhitespace(text, true));
+ base::string16 collapsed_text(base::CollapseWhitespace(text, true));
if (model()->CanPasteAndGo(collapsed_text))
model()->PasteAndGo(collapsed_text);
return ui::DragDropTypes::DRAG_COPY;
menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
- if (chrome::IsQueryExtractionEnabled() || chrome::ShouldDisplayOriginChip()) {
+ if (chrome::IsQueryExtractionEnabled() || chrome::ShouldDisplayOriginChip() ||
+ chrome::ShouldDisplayOriginChipV2()) {
int select_all_position = menu_contents->GetIndexOfCommandId(
IDS_APP_SELECT_ALL);
DCHECK_GE(select_all_position, 0);