Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2833)

Unified Diff: chrome/browser/instant/instant_controller_utils.cc

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/instant/instant_controller_utils.cc
diff --git a/chrome/browser/instant/instant_controller_utils.cc b/chrome/browser/instant/instant_controller_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d524837e8325d5d8eaf48fce1c33bd784446a75c
--- /dev/null
+++ b/chrome/browser/instant/instant_controller_utils.cc
@@ -0,0 +1,126 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/instant/instant_controller_utils.h"
+
+#include "chrome/browser/platform_util.h"
+#include "content/public/browser/render_widget_host_view.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "third_party/icu/public/common/unicode/normalizer2.h"
+
+#if defined(TOOLKIT_VIEWS)
+#include "ui/views/widget/widget.h"
+#endif
+
+namespace {
+
+string16 Normalize(const string16& str) {
+ UErrorCode status = U_ZERO_ERROR;
+ const icu::Normalizer2* normalizer =
+ icu::Normalizer2::getInstance(NULL, "nfkc_cf", UNORM2_COMPOSE, status);
+ if (normalizer == NULL || U_FAILURE(status))
+ return str;
+ icu::UnicodeString norm_str(normalizer->normalize(
+ icu::UnicodeString(FALSE, str.c_str(), str.size()), status));
+ if (U_FAILURE(status))
+ return str;
+ return string16(norm_str.getBuffer(), norm_str.length());
+}
+
+} // namespace
+
+// static
+gfx::NativeView InstantControllerUtils::GetViewGainingFocus(
+ gfx::NativeView view_gaining_focus) {
+#if defined(TOOLKIT_VIEWS)
+ // For TOOLKIT_VIEWS, the top level widget is always focused. If the focus
+ // change originated in views determine the child Widget from the view that is
+ // being focused.
+ views::Widget* widget = view_gaining_focus ?
+ views::Widget::GetWidgetForNativeView(view_gaining_focus) : NULL;
+ if (widget) {
+ views::FocusManager* focus_manager = widget->GetFocusManager();
+ if (focus_manager && focus_manager->is_changing_focus() &&
+ focus_manager->GetFocusedView() &&
+ focus_manager->GetFocusedView()->GetWidget())
+ return focus_manager->GetFocusedView()->GetWidget()->GetNativeView();
+ }
+#endif
+ return view_gaining_focus;
+}
+
+// static
+bool InstantControllerUtils::IsViewInContents(gfx::NativeView view,
+ content::WebContents* contents) {
+ content::RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView();
+ if (!view || !rwhv)
+ return false;
+
+ gfx::NativeView tab_view = contents->GetView()->GetNativeView();
+ if (view == rwhv->GetNativeView() || view == tab_view)
+ return true;
+
+ // Walk up the view hierarchy to determine if the view is a subview of the
+ // WebContents view (such as a windowed plugin or http auth dialog).
+ while (view) {
+ view = platform_util::GetParent(view);
+ if (view == tab_view)
+ return true;
+ }
+
+ return false;
+}
+
+// static
+bool InstantControllerUtils::NormalizeAndStripPrefix(string16* text,
+ const string16& prefix) {
+ string16 norm_prefix = Normalize(prefix);
+ string16 norm_text = Normalize(*text);
+ if (norm_prefix.size() <= norm_text.size() &&
+ norm_text.compare(0, norm_prefix.size(), norm_prefix) == 0) {
+ *text = norm_text.erase(0, norm_prefix.size());
+ return true;
+ }
+ return false;
+}
+
+// static
+std::string InstantControllerUtils::CommitTypeToString(InstantCommitType type) {
+ switch (type) {
+ case INSTANT_COMMIT_PRESSED_ENTER: return "enter";
+ case INSTANT_COMMIT_PRESSED_ALT_ENTER: return "alt-enter";
+ case INSTANT_COMMIT_FOCUS_LOST: return "focus-lost";
+ case INSTANT_COMMIT_NAVIGATED: return "navigated";
+ }
+
+ NOTREACHED();
+ return std::string();
+}
+
+// static
+std::string InstantControllerUtils::FocusStateToString(
+ OmniboxFocusState state) {
+ switch (state) {
+ case OMNIBOX_FOCUS_NONE: return "none";
+ case OMNIBOX_FOCUS_VISIBLE: return "visible";
+ case OMNIBOX_FOCUS_INVISIBLE: return "invisible";
+ }
+
+ NOTREACHED();
+ return std::string();
+}
+
+// static
+std::string InstantControllerUtils::FocusChangeReasonToString(
+ OmniboxFocusChangeReason reason) {
+ switch (reason) {
+ case OMNIBOX_FOCUS_CHANGE_EXPLICIT: return "explicit";
+ case OMNIBOX_FOCUS_CHANGE_TAB_SWITCH: return "tab-switch";
+ case OMNIBOX_FOCUS_CHANGE_TYPING: return "typing";
+ }
+
+ NOTREACHED();
+ return std::string();
+}

Powered by Google App Engine
This is Rietveld 408576698