summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 19:40:33 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 19:40:33 +0000
commitfb5153c5dd44a771be0cbd030a02eccf5cde76ed (patch)
treef1533b6d48fc5d4bc88729cb4a7fa885ca6e7d1a /chrome
parent7df4348513bd316224dbc1399990a2538c55a5bc (diff)
downloadchromium_src-fb5153c5dd44a771be0cbd030a02eccf5cde76ed.zip
chromium_src-fb5153c5dd44a771be0cbd030a02eccf5cde76ed.tar.gz
chromium_src-fb5153c5dd44a771be0cbd030a02eccf5cde76ed.tar.bz2
Make TOOLKIT_VIEWS port use views-based Autocomplete popup.
The popups now interact with the edit via AutocompleteEditView rather than the platform-specific types. Note this also removes the old omnibox popup code. It hasn't been active for some time. BUG=none TEST=none Review URL: http://codereview.chromium.org/160378 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view.h4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc11
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h5
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm12
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.h1
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view.h6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc15
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.h6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_win.cc692
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_win.h210
-rw-r--r--chrome/browser/autocomplete/search_provider.cc105
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc52
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h14
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc50
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_gtk.h37
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_win.cc14
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_win.h10
-rw-r--r--chrome/chrome.gyp12
-rw-r--r--chrome/common/chrome_switches.cc2
-rw-r--r--chrome/common/chrome_switches.h2
22 files changed, 255 insertions, 1012 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h
index b8b438f..2003af5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view.h
@@ -13,6 +13,7 @@
#include <string>
+#include "base/gfx/native_widget_types.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/window_open_disposition.h"
@@ -121,6 +122,9 @@ class AutocompleteEditView {
// OnAfterPossibleChange() returns true if there was a change that caused it
// to call UpdatePopup().
virtual bool OnAfterPossibleChange() = 0;
+
+ // Returns the gfx::NativeView of the edit view.
+ virtual gfx::NativeView GetNativeView() const = 0;
};
#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_VIEW_H_
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 8c5dbf9..9e911a1 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -7,6 +7,7 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include "app/gfx/font.h"
#include "app/l10n_util.h"
#include "base/gfx/gtk_util.h"
#include "base/logging.h"
@@ -79,8 +80,10 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
secure_scheme_tag_(NULL),
insecure_scheme_tag_(NULL),
model_(new AutocompleteEditModel(this, controller, profile)),
- popup_view_(new AutocompletePopupViewGtk(this, model_.get(), profile,
- popup_positioner)),
+ popup_view_(AutocompletePopupView::CreatePopupView(gfx::Font(), this,
+ model_.get(),
+ profile,
+ popup_positioner)),
controller_(controller),
toolbar_model_(toolbar_model),
command_updater_(command_updater),
@@ -428,6 +431,10 @@ bool AutocompleteEditViewGtk::OnAfterPossibleChange() {
return something_changed;
}
+gfx::NativeView AutocompleteEditViewGtk::GetNativeView() const {
+ return alignment_.get();
+}
+
void AutocompleteEditViewGtk::HandleBeginUserAction() {
OnBeforePossibleChange();
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 3c1c491..bd91442 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -19,7 +19,7 @@
class AutocompleteEditController;
class AutocompleteEditModel;
class AutocompletePopupPositioner;
-class AutocompletePopupViewGtk;
+class AutocompletePopupView;
class CommandUpdater;
class Profile;
class TabContents;
@@ -97,6 +97,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
virtual void OnRevertTemporaryText();
virtual void OnBeforePossibleChange();
virtual bool OnAfterPossibleChange();
+ virtual gfx::NativeView GetNativeView() const;
private:
// TODO(deanm): Would be nice to insulate the thunkers better, etc.
@@ -287,7 +288,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
GtkTextTag* black_text_tag_;
scoped_ptr<AutocompleteEditModel> model_;
- scoped_ptr<AutocompletePopupViewGtk> popup_view_;
+ scoped_ptr<AutocompletePopupView> popup_view_;
AutocompleteEditController* controller_;
ToolbarModel* toolbar_model_;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index 854099b..b82ec01 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -83,6 +83,7 @@ class AutocompleteEditViewMac : public AutocompleteEditView {
virtual void OnRevertTemporaryText();
virtual void OnBeforePossibleChange();
virtual bool OnAfterPossibleChange();
+ virtual gfx::NativeView GetNativeView() const;
// Helper functions for use from AutocompleteEditHelper Objective-C
// class.
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index d1f8f31..84f6d0d 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -161,7 +161,7 @@ AutocompleteEditViewMac::AutocompleteEditViewMac(
// |model_|.
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:edit_helper_
- selector:@selector(windowDidResignKey:)
+ selector:@selector(windowDidResignKey:)
name:NSWindowDidResignKeyNotification
object:[field_ window]];
}
@@ -216,7 +216,7 @@ void AutocompleteEditViewMac::Update(
if (tab_for_state_restoring) {
RevertAll();
- const AutocompleteEditViewMacState* state =
+ const AutocompleteEditViewMacState* state =
GetStateFromTab(tab_for_state_restoring);
if (state) {
// Should restore the user's text via SetUserText().
@@ -511,6 +511,10 @@ bool AutocompleteEditViewMac::OnAfterPossibleChange() {
return something_changed;
}
+gfx::NativeView AutocompleteEditViewMac::GetNativeView() const {
+ return field_;
+}
+
void AutocompleteEditViewMac::OnUpOrDownKeyPressed(bool up, bool by_page) {
// We should only arrive here when the field is focussed.
DCHECK(IsFirstResponder());
@@ -661,12 +665,12 @@ std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) {
return YES;
}
}
-
+
if (cmd == @selector(scrollPageDown:)) {
edit_view_->OnUpOrDownKeyPressed(false, true);
return YES;
}
-
+
if (cmd == @selector(scrollPageUp:)) {
edit_view_->OnUpOrDownKeyPressed(true, true);
return YES;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index ca6040a..5e88e94 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -23,7 +23,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete_accessibility.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
-#include "chrome/browser/autocomplete/autocomplete_popup_view_win.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/command_updater.h"
@@ -874,6 +874,10 @@ bool AutocompleteEditViewWin::OnAfterPossibleChange() {
return something_changed;
}
+gfx::NativeView AutocompleteEditViewWin::GetNativeView() const {
+ return m_hWnd;
+}
+
void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) {
if (CanPasteAndGo(text))
model_->PasteAndGo();
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
index 986e799..9f5dc95 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
@@ -116,6 +116,7 @@ class AutocompleteEditViewWin
virtual void OnRevertTemporaryText();
virtual void OnBeforePossibleChange();
virtual bool OnAfterPossibleChange();
+ virtual gfx::NativeView GetNativeView() const;
// Exposes custom IAccessible implementation to the overall MSAA hierarchy.
IAccessible* GetIAccessible();
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view.h b/chrome/browser/autocomplete/autocomplete_popup_view.h
index 9ccb614..32cc0df 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view.h
@@ -19,7 +19,7 @@ namespace gfx {
class Font;
class Rect;
}
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
class AutocompleteEditViewWin;
class AutocompleteEditModel;
class Profile;
@@ -58,12 +58,12 @@ class AutocompletePopupView {
// Returns the popup's model.
virtual AutocompletePopupModel* GetModel() = 0;
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
// Create a popup view implementation. It may make sense for this to become
// platform independent eventually.
static AutocompletePopupView* CreatePopupView(
const gfx::Font& font,
- AutocompleteEditViewWin* edit_view,
+ AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
AutocompletePopupPositioner* popup_positioner);
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index ad197aa..dffc91a 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -18,7 +18,7 @@
#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
-#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
+#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/profile.h"
@@ -235,7 +235,7 @@ GdkPixbuf* IconForMatch(const AutocompleteMatch& match, bool selected) {
} // namespace
AutocompletePopupViewGtk::AutocompletePopupViewGtk(
- AutocompleteEditViewGtk* edit_view,
+ AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
AutocompletePopupPositioner* popup_positioner)
@@ -508,3 +508,14 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
return TRUE;
}
+
+// static
+AutocompletePopupView* AutocompletePopupView::CreatePopupView(
+ const gfx::Font& font,
+ AutocompleteEditView* edit_view,
+ AutocompleteEditModel* edit_model,
+ Profile* profile,
+ AutocompletePopupPositioner* popup_positioner) {
+ return new AutocompletePopupViewGtk(edit_view, edit_model, profile,
+ popup_positioner);
+}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
index bed813b..b176348 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
@@ -13,14 +13,14 @@
#include "webkit/glue/window_open_disposition.h"
class AutocompleteEditModel;
-class AutocompleteEditViewGtk;
+class AutocompleteEditView;
class AutocompletePopupModel;
class Profile;
class SkBitmap;
class AutocompletePopupViewGtk : public AutocompletePopupView {
public:
- AutocompletePopupViewGtk(AutocompleteEditViewGtk* edit_view,
+ AutocompletePopupViewGtk(AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
AutocompletePopupPositioner* popup_positioner);
@@ -75,7 +75,7 @@ class AutocompletePopupViewGtk : public AutocompletePopupView {
gboolean HandleButtonRelease(GtkWidget* widget, GdkEventButton* event);
scoped_ptr<AutocompletePopupModel> model_;
- AutocompleteEditViewGtk* edit_view_;
+ AutocompleteEditView* edit_view_;
AutocompletePopupPositioner* popup_positioner_;
// Our popup window, which is the only widget used, and we paint it on our
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_win.cc b/chrome/browser/autocomplete/autocomplete_popup_view_win.cc
deleted file mode 100644
index 7a0c9f6..0000000
--- a/chrome/browser/autocomplete/autocomplete_popup_view_win.cc
+++ /dev/null
@@ -1,692 +0,0 @@
-// Copyright (c) 2006-2008 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/autocomplete/autocomplete_popup_view_win.h"
-
-// TODO(deanm): Clean up these includes, not going to fight it now.
-#include <atlbase.h>
-#include <atlapp.h>
-#include <atlcrack.h>
-#include <atlmisc.h>
-#include <cmath>
-
-#include "app/gfx/canvas.h"
-#include "app/gfx/font.h"
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "base/command_line.h"
-#include "base/string_util.h"
-#include "base/win_util.h"
-#include "chrome/browser/autocomplete/autocomplete.h"
-#include "chrome/browser/autocomplete/autocomplete_edit.h"
-#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/net/dns_global.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
-#include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h"
-#include "chrome/browser/views/location_bar_view.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/notification_service.h"
-#include "grit/theme_resources.h"
-#include "third_party/icu38/public/common/unicode/ubidi.h"
-#include "views/view.h"
-
-// Padding between text and the star indicator, in pixels.
-static const int kStarPadding = 4;
-
-// This class implements a utility used for mirroring x-coordinates when the
-// application language is a right-to-left one.
-class AutocompletePopupViewWin::MirroringContext {
- public:
- MirroringContext() : min_x_(0), center_x_(0), max_x_(0), enabled_(false) { }
-
- // Initializes the bounding region used for mirroring coordinates.
- // This class uses the center of this region as an axis for calculating
- // mirrored coordinates.
- void Initialize(int x1, int x2, bool enabled);
-
- // Return the "left" side of the specified region.
- // When the application language is a right-to-left one, this function
- // calculates the mirrored coordinates of the input region and returns the
- // left side of the mirrored region.
- // The input region must be in the bounding region specified in the
- // Initialize() function.
- int GetLeft(int x1, int x2) const;
-
- // Returns whether or not we are mirroring the x coordinate.
- bool enabled() const {
- return enabled_;
- }
-
- private:
- int min_x_;
- int center_x_;
- int max_x_;
- bool enabled_;
-
- DISALLOW_EVIL_CONSTRUCTORS(MirroringContext);
-};
-
-void AutocompletePopupViewWin::MirroringContext::Initialize(int x1,
- int x2,
- bool enabled) {
- min_x_ = std::min(x1, x2);
- max_x_ = std::max(x1, x2);
- center_x_ = min_x_ + (max_x_ - min_x_) / 2;
- enabled_ = enabled;
-}
-
-int AutocompletePopupViewWin::MirroringContext::GetLeft(int x1, int x2) const {
- return enabled_ ?
- (center_x_ + (center_x_ - std::max(x1, x2))) : std::min(x1, x2);
-}
-
-const wchar_t AutocompletePopupViewWin::DrawLineInfo::ellipsis_str[] =
- L"\x2026";
-
-AutocompletePopupViewWin::DrawLineInfo::DrawLineInfo(const gfx::Font& font) {
- // Create regular and bold fonts.
- regular_font = font.DeriveFont(-1);
- bold_font = regular_font.DeriveFont(0, gfx::Font::BOLD);
-
- // The total padding added to each line (bottom padding is what is
- // left over after DrawEntry() specifies its top offset).
- static const int kTotalLinePadding = 5;
- font_height = std::max(regular_font.height(), bold_font.height());
- line_height = font_height + kTotalLinePadding;
- ave_char_width = regular_font.GetExpectedTextWidth(1);
- ellipsis_width = std::max(regular_font.GetStringWidth(ellipsis_str),
- bold_font.GetStringWidth(ellipsis_str));
-
- // Create background colors.
- background_colors[NORMAL] = GetSysColor(COLOR_WINDOW);
- background_colors[SELECTED] = GetSysColor(COLOR_HIGHLIGHT);
- background_colors[HOVERED] =
- AlphaBlend(background_colors[SELECTED], background_colors[NORMAL], 0x40);
-
- // Create text colors.
- text_colors[NORMAL] = GetSysColor(COLOR_WINDOWTEXT);
- text_colors[HOVERED] = text_colors[NORMAL];
- text_colors[SELECTED] = GetSysColor(COLOR_HIGHLIGHTTEXT);
-
- // Create brushes and url colors.
- const COLORREF dark_url(0x008000);
- const COLORREF light_url(0xd0ffd0);
- for (int i = 0; i < MAX_STATUS_ENTRIES; ++i) {
- // Pick whichever URL color contrasts better.
- const double dark_contrast =
- LuminosityContrast(dark_url, background_colors[i]);
- const double light_contrast =
- LuminosityContrast(light_url, background_colors[i]);
- url_colors[i] = (dark_contrast > light_contrast) ? dark_url : light_url;
-
- brushes[i] = CreateSolidBrush(background_colors[i]);
- }
-}
-
-AutocompletePopupViewWin::DrawLineInfo::~DrawLineInfo() {
- for (int i = 0; i < MAX_STATUS_ENTRIES; ++i)
- DeleteObject(brushes[i]);
-}
-
-// static
-double AutocompletePopupViewWin::DrawLineInfo::LuminosityContrast(
- COLORREF color1,
- COLORREF color2) {
- // This algorithm was adapted from the following text at
- // http://juicystudio.com/article/luminositycontrastratioalgorithm.php :
- //
- // "[Luminosity contrast can be calculated as] (L1+.05) / (L2+.05) where L is
- // luminosity and is defined as .2126*R + .7152*G + .0722B using linearised
- // R, G, and B values. Linearised R (for example) = (R/FS)^2.2 where FS is
- // full scale value (255 for 8 bit color channels). L1 is the higher value
- // (of text or background) and L2 is the lower value.
- //
- // The Gamma correction and RGB constants are derived from the Standard
- // Default Color Space for the Internet (sRGB), and the 0.05 offset is
- // included to compensate for contrast ratios that occur when a value is at
- // or near zero, and for ambient light effects.
- const double l1 = Luminosity(color1);
- const double l2 = Luminosity(color2);
- return (l1 > l2) ? ((l1 + 0.05) / (l2 + 0.05)) : ((l2 + 0.05) / (l1 + 0.05));
-}
-
-// static
-double AutocompletePopupViewWin::DrawLineInfo::Luminosity(COLORREF color) {
- // See comments in LuminosityContrast().
- const double linearised_r =
- pow(static_cast<double>(GetRValue(color)) / 255.0, 2.2);
- const double linearised_g =
- pow(static_cast<double>(GetGValue(color)) / 255.0, 2.2);
- const double linearised_b =
- pow(static_cast<double>(GetBValue(color)) / 255.0, 2.2);
- return (0.2126 * linearised_r) + (0.7152 * linearised_g) +
- (0.0722 * linearised_b);
-}
-
-COLORREF AutocompletePopupViewWin::DrawLineInfo::AlphaBlend(
- COLORREF foreground,
- COLORREF background,
- BYTE alpha) {
- if (alpha == 0)
- return background;
- else if (alpha == 0xff)
- return foreground;
-
- return RGB(
- ((GetRValue(foreground) * alpha) +
- (GetRValue(background) * (0xff - alpha))) / 0xff,
- ((GetGValue(foreground) * alpha) +
- (GetGValue(background) * (0xff - alpha))) / 0xff,
- ((GetBValue(foreground) * alpha) +
- (GetBValue(background) * (0xff - alpha))) / 0xff);
-}
-
-AutocompletePopupViewWin::AutocompletePopupViewWin(
- const gfx::Font& font,
- AutocompleteEditViewWin* edit_view,
- AutocompleteEditModel* edit_model,
- Profile* profile)
- : model_(new AutocompletePopupModel(this, edit_model, profile)),
- edit_view_(edit_view),
- line_info_(font),
- mirroring_context_(new MirroringContext()),
- star_(ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_CONTENT_STAR_ON)) {
-}
-
-void AutocompletePopupViewWin::InvalidateLine(size_t line) {
- RECT rc;
- GetClientRect(&rc);
- rc.top = LineTopPixel(line);
- rc.bottom = rc.top + line_info_.line_height;
- InvalidateRect(&rc, false);
-}
-
-void AutocompletePopupViewWin::UpdatePopupAppearance() {
- const AutocompleteResult& result = model_->result();
- if (result.empty()) {
- // No matches, close any existing popup.
- if (m_hWnd) {
- DestroyWindow();
- m_hWnd = NULL;
- }
- return;
- }
-
- // Figure the coordinates of the popup:
- // Get the coordinates of the location bar view; these are returned relative
- // to its parent.
- // TODO(pkasting): http://b/1345937 All this use of editor accessors should
- // die once this class is a true ChromeView.
- CRect rc = edit_view_->parent_view()->bounds().ToRECT();
- // Subtract the top left corner to make the coordinates relative to the
- // location bar view itself, and convert to screen coordinates.
- gfx::Point top_left(-rc.TopLeft());
- views::View::ConvertPointToScreen(edit_view_->parent_view(), &top_left);
- rc.OffsetRect(top_left.ToPOINT());
- // Expand by one pixel on each side since that's the amount the location bar
- // view is inset from the divider line that edges the adjacent buttons.
- // Deflate the top and bottom by the height of the extra graphics around the
- // edit.
- // TODO(pkasting): http://b/972786 This shouldn't be hardcoded to rely on
- // LocationBarView constants. Instead we should just make the edit be "at the
- // right coordinates", or something else generic.
- rc.InflateRect(1, -LocationBarView::kVertMargin);
- // Now rc is the exact width we want and is positioned like the edit would
- // be, so shift the top and bottom downwards so the new top is where the old
- // bottom is and the rect has the height we need for all our entries, plus a
- // one-pixel border on top and bottom.
- rc.top = rc.bottom;
- rc.bottom += static_cast<int>(result.size()) * line_info_.line_height + 2;
-
- if (!m_hWnd) {
- // To prevent this window from being activated, we create an invisible
- // window and manually show it without activating it.
- Create(edit_view_->m_hWnd, rc, AUTOCOMPLETEPOPUPVIEW_CLASSNAME, WS_POPUP,
- WS_EX_TOOLWINDOW);
- // When an IME is attached to the rich-edit control, retrieve its window
- // handle and show this popup window under the IME windows.
- // Otherwise, show this popup window under top-most windows.
- // TODO(hbono): http://b/1111369 if we exclude this popup window from the
- // display area of IME windows, this workaround becomes unnecessary.
- HWND ime_window = ImmGetDefaultIMEWnd(edit_view_->m_hWnd);
- SetWindowPos(ime_window ? ime_window : HWND_NOTOPMOST, 0, 0, 0, 0,
- SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
- } else {
- // Already open, just resize the window. This is a bit tricky; we want to
- // repaint the whole window, since the contents may have changed, but
- // MoveWindow() won't repaint portions that haven't moved or been
- // added/removed. So we first call InvalidateRect(), so the next repaint
- // paints the whole window, then tell MoveWindow() to do the actual
- // repaint, which will also properly repaint Windows formerly under the
- // popup.
- InvalidateRect(NULL, false);
- MoveWindow(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, true);
- }
-
- // TODO(pkasting): http://b/1111369 We should call ImmSetCandidateWindow() on
- // the edit_view_'s IME context here, and exclude ourselves from its display
- // area. Not clear what to pass for the lpCandidate->ptCurrentPos member,
- // though...
-}
-
-void AutocompletePopupViewWin::OnHoverEnabledOrDisabled(bool disabled) {
- TRACKMOUSEEVENT tme;
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- if (disabled) {
- // Save the current mouse position to check against for re-enabling.
- GetCursorPos(&last_hover_coordinates_); // Returns screen coordinates
-
- // Cancel existing registration for WM_MOUSELEAVE notifications.
- tme.dwFlags = TME_CANCEL | TME_LEAVE;
- } else {
- // Register for WM_MOUSELEAVE notifications.
- tme.dwFlags = TME_LEAVE;
- }
- tme.hwndTrack = m_hWnd;
- tme.dwHoverTime = HOVER_DEFAULT; // Not actually used
- TrackMouseEvent(&tme);
-}
-
-void AutocompletePopupViewWin::OnLButtonDown(UINT keys, const CPoint& point) {
- const size_t new_hovered_line = PixelToLine(point.y);
- model_->SetHoveredLine(new_hovered_line);
- model_->SetSelectedLine(new_hovered_line, false);
-}
-
-void AutocompletePopupViewWin::OnMButtonDown(UINT keys, const CPoint& point) {
- model_->SetHoveredLine(PixelToLine(point.y));
-}
-
-void AutocompletePopupViewWin::OnLButtonUp(UINT keys, const CPoint& point) {
- OnButtonUp(point, CURRENT_TAB);
-}
-
-void AutocompletePopupViewWin::OnMButtonUp(UINT keys, const CPoint& point) {
- OnButtonUp(point, NEW_BACKGROUND_TAB);
-}
-
-LRESULT AutocompletePopupViewWin::OnMouseActivate(HWND window,
- UINT hit_test,
- UINT mouse_message) {
- return MA_NOACTIVATE;
-}
-
-void AutocompletePopupViewWin::OnMouseLeave() {
- // The mouse has left the window, so no line is hovered.
- model_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
-}
-
-void AutocompletePopupViewWin::OnMouseMove(UINT keys, const CPoint& point) {
- // Track hover when
- // (a) The left or middle button is down (the user is interacting via the
- // mouse)
- // (b) The user moves the mouse from where we last stopped tracking hover
- // (c) We started tracking previously due to (a) or (b) and haven't stopped
- // yet (user hasn't used the keyboard to interact again)
- const bool action_button_pressed = !!(keys & (MK_MBUTTON | MK_LBUTTON));
- CPoint screen_point(point);
- ClientToScreen(&screen_point);
- if (action_button_pressed || (last_hover_coordinates_ != screen_point) ||
- (model_->hovered_line() != AutocompletePopupModel::kNoMatch)) {
- // Determine the hovered line from the y coordinate of the event. We don't
- // need to check whether the x coordinates are within the window since if
- // they weren't someone else would have received the WM_MOUSEMOVE.
- const size_t new_hovered_line = PixelToLine(point.y);
- model_->SetHoveredLine(new_hovered_line);
-
- // When the user has the left button down, update their selection
- // immediately (don't wait for mouseup).
- if (keys & MK_LBUTTON)
- model_->SetSelectedLine(new_hovered_line, false);
- }
-}
-
-void AutocompletePopupViewWin::OnPaint(HDC other_dc) {
- const AutocompleteResult& result = model_->result();
- CHECK(!result.empty()); // Shouldn't be drawing an empty popup; any empty
- // result set should have synchronously closed us.
-
- CPaintDC dc(m_hWnd);
-
- RECT rc;
- GetClientRect(&rc);
- mirroring_context_->Initialize(rc.left, rc.right,
- l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT);
- DrawBorder(rc, dc);
-
- bool all_descriptions_empty = true;
- for (AutocompleteResult::const_iterator i(result.begin()); i != result.end();
- ++i) {
- if (!i->description.empty()) {
- all_descriptions_empty = false;
- break;
- }
- }
-
- // Only repaint the invalid lines.
- // In rare cases, it seems possible to get line offsets off the end of the
- // popup. I suspect this can happen when the user invalidates a new line
- // (e.g. by moving the mouse) and, before the paint request is serviced, hits
- // a key that causes autocomplete to run, causing the results list to become
- // shorter (at least initially). So sanitize the line numbers here.
- const size_t last_valid_line = result.size() - 1;
- const size_t first_line = PixelToLine(dc.m_ps.rcPaint.top);
- if (first_line > last_valid_line)
- return;
- const size_t last_line =
- std::min(PixelToLine(dc.m_ps.rcPaint.bottom), last_valid_line);
-
- for (size_t i = first_line; i <= last_line; ++i) {
- DrawLineInfo::LineStatus status;
- // Selection should take precedence over hover.
- if (i == model_->selected_line())
- status = DrawLineInfo::SELECTED;
- else if (i == model_->hovered_line())
- status = DrawLineInfo::HOVERED;
- else
- status = DrawLineInfo::NORMAL;
- DrawEntry(dc, rc, i, status, all_descriptions_empty,
- result.match_at(i).starred);
- }
-}
-
-void AutocompletePopupViewWin::OnButtonUp(const CPoint& point,
- WindowOpenDisposition disposition) {
- const size_t line = PixelToLine(point.y);
- const AutocompleteMatch& match = model_->result().match_at(line);
- // OpenURL() may close the popup, which will clear the result set and, by
- // extension, |match| and its contents. So copy the relevant strings out to
- // make sure they stay alive until the call completes.
- const GURL url(match.destination_url);
- std::wstring keyword;
- const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword);
- edit_view_->OpenURL(url, disposition, match.transition, GURL(), line,
- is_keyword_hint ? std::wstring() : keyword);
-}
-
-int AutocompletePopupViewWin::LineTopPixel(size_t line) const {
- // The popup has a 1 px top border.
- return line_info_.line_height * static_cast<int>(line) + 1;
-}
-
-size_t AutocompletePopupViewWin::PixelToLine(int y) const {
- const size_t line = std::max(y - 1, 0) / line_info_.line_height;
- return std::min(line, model_->result().size() - 1);
-}
-
-// Draws a light border around the inside of the window with the given client
-// rectangle and DC.
-void AutocompletePopupViewWin::DrawBorder(const RECT& rc, HDC dc) {
- HPEN hpen = CreatePen(PS_SOLID, 1, RGB(199, 202, 206));
- HGDIOBJ old_pen = SelectObject(dc, hpen);
-
- int width = rc.right - rc.left - 1;
- int height = rc.bottom - rc.top - 1;
-
- MoveToEx(dc, 0, 0, NULL);
- LineTo(dc, 0, height);
- LineTo(dc, width, height);
- LineTo(dc, width, 0);
- LineTo(dc, 0, 0);
-
- SelectObject(dc, old_pen);
- DeleteObject(hpen);
-}
-
-int AutocompletePopupViewWin::DrawString(HDC dc,
- int x,
- int y,
- int max_x,
- const wchar_t* text,
- int length,
- int style,
- const DrawLineInfo::LineStatus status,
- const MirroringContext* context,
- bool text_direction_is_rtl) const {
- if (length <= 0)
- return 0;
-
- // Set up the text decorations.
- SelectObject(dc, (style & ACMatchClassification::MATCH) ?
- line_info_.bold_font.hfont() : line_info_.regular_font.hfont());
- const COLORREF foreground = (style & ACMatchClassification::URL) ?
- line_info_.url_colors[status] : line_info_.text_colors[status];
- const COLORREF background = line_info_.background_colors[status];
- SetTextColor(dc, (style & ACMatchClassification::DIM) ?
- DrawLineInfo::AlphaBlend(foreground, background, 0xAA) : foreground);
-
- // Retrieve the width of the decorated text and display it. When we cannot
- // display this fragment in the given width, we trim the fragment and add an
- // ellipsis.
- //
- // TODO(hbono): http:///b/1222425 We should change the following eliding code
- // with more aggressive one.
- int text_x = x;
- int max_length = 0;
- SIZE text_size = {0};
- GetTextExtentExPoint(dc, text, length,
- max_x - line_info_.ellipsis_width - text_x, &max_length,
- NULL, &text_size);
-
- if (max_length < length)
- GetTextExtentPoint32(dc, text, max_length, &text_size);
-
- const int mirrored_x = context->GetLeft(text_x, text_x + text_size.cx);
- RECT text_bounds = {mirrored_x,
- 0,
- mirrored_x + text_size.cx,
- line_info_.line_height};
-
- int flags = DT_SINGLELINE | DT_NOPREFIX;
- if (text_direction_is_rtl)
- // In order to make sure RTL text is displayed correctly (for example, a
- // trailing space should be displayed on the left and not on the right), we
- // pass the flag DT_RTLREADING.
- flags |= DT_RTLREADING;
-
- DrawText(dc, text, length, &text_bounds, flags);
- text_x += text_size.cx;
-
- // Draw the ellipsis. Note that since we use the mirroring context, the
- // ellipsis are drawn either to the right or to the left of the text.
- if (max_length < length) {
- TextOut(dc, context->GetLeft(text_x, text_x + line_info_.ellipsis_width),
- 0, line_info_.ellipsis_str, arraysize(line_info_.ellipsis_str) - 1);
- text_x += line_info_.ellipsis_width;
- }
-
- return text_x - x;
-}
-
-void AutocompletePopupViewWin::DrawMatchFragments(
- HDC dc,
- const std::wstring& text,
- const ACMatchClassifications& classifications,
- int x,
- int y,
- int max_x,
- DrawLineInfo::LineStatus status) const {
- if (!text.length())
- return;
-
- // Check whether or not this text is a URL string.
- // A URL string is basically in English with possible included words in
- // Arabic or Hebrew. For such case, ICU provides a special algorithm and we
- // should use it.
- bool url = false;
- for (ACMatchClassifications::const_iterator i = classifications.begin();
- i != classifications.end(); ++i) {
- if (i->style & ACMatchClassification::URL)
- url = true;
- }
-
- // Initialize a bidirectional line iterator of ICU and split the text into
- // visual runs. (A visual run is consecutive characters which have the same
- // display direction and should be displayed at once.)
- l10n_util::BiDiLineIterator bidi_line;
- if (!bidi_line.Open(text, mirroring_context_->enabled(), url))
- return;
- const int runs = bidi_line.CountRuns();
-
- // Draw the visual runs.
- // This loop splits each run into text fragments with the given
- // classifications and draws the text fragments.
- // When the direction of a run is right-to-left, we have to mirror the
- // x-coordinate of this run and render the fragments in the right-to-left
- // reading order. To handle this display order independently from the one of
- // this popup window, this loop renders a run with the steps below:
- // 1. Create a local display context for each run;
- // 2. Render the run into the local display context, and;
- // 3. Copy the local display context to the one of the popup window.
- int run_x = x;
- for (int run = 0; run < runs; ++run) {
- int run_start = 0;
- int run_length = 0;
-
- // The index we pass to GetVisualRun corresponds to the position of the run
- // in the displayed text. For example, the string "Google in HEBREW" (where
- // HEBREW is text in the Hebrew language) has two runs: "Google in " which
- // is an LTR run, and "HEBREW" which is an RTL run. In an LTR context, the
- // run "Google in " has the index 0 (since it is the leftmost run
- // displayed). In an RTL context, the same run has the index 1 because it
- // is the rightmost run. This is why the order in which we traverse the
- // runs is different depending on the locale direction.
- //
- // Note that for URLs we always traverse the runs from lower to higher
- // indexes because the return order of runs for a URL always matches the
- // physical order of the context.
- int current_run =
- (mirroring_context_->enabled() && !url) ? (runs - run - 1) : run;
- const UBiDiDirection run_direction = bidi_line.GetVisualRun(current_run,
- &run_start,
- &run_length);
- const int run_end = run_start + run_length;
-
- // Set up a local display context for rendering this run.
- int text_x = 0;
- const int text_max_x = max_x - run_x;
- MirroringContext run_context;
- run_context.Initialize(0, text_max_x, run_direction == UBIDI_RTL);
-
- // In addition to creating a mirroring context for the run, we indicate
- // whether the run needs to be rendered as RTL text. The mirroring context
- // alone in not sufficient because there are cases where a mirrored RTL run
- // needs to be rendered in an LTR context (for example, an RTL run within
- // an URL).
- bool run_direction_is_rtl = (run_direction == UBIDI_RTL) && !url;
- CDC text_dc(CreateCompatibleDC(dc));
- CBitmap text_bitmap(CreateCompatibleBitmap(dc, text_max_x,
- line_info_.font_height));
- SelectObject(text_dc, text_bitmap);
- const RECT text_rect = {0, 0, text_max_x, line_info_.line_height};
- FillRect(text_dc, &text_rect, line_info_.brushes[status]);
- SetBkMode(text_dc, TRANSPARENT);
-
- // Split this run with the given classifications and draw the fragments
- // into the local display context.
- for (ACMatchClassifications::const_iterator i = classifications.begin();
- i != classifications.end(); ++i) {
- const int text_start = std::max(run_start, static_cast<int>(i->offset));
- const int text_end = std::min(run_end, (i != classifications.end() - 1) ?
- static_cast<int>((i + 1)->offset) : run_end);
- text_x += DrawString(text_dc, text_x, 0, text_max_x, &text[text_start],
- text_end - text_start, i->style, status,
- &run_context, run_direction_is_rtl);
- }
-
- // Copy the local display context to the one of the popup window and
- // delete the local display context.
- BitBlt(dc, mirroring_context_->GetLeft(run_x, run_x + text_x), y, text_x,
- line_info_.line_height, text_dc, run_context.GetLeft(0, text_x), 0,
- SRCCOPY);
- run_x += text_x;
- }
-}
-
-void AutocompletePopupViewWin::DrawEntry(HDC dc,
- const RECT& client_rect,
- size_t line,
- DrawLineInfo::LineStatus status,
- bool all_descriptions_empty,
- bool starred) const {
- // Calculate outer bounds of entry, and fill background.
- const int top_pixel = LineTopPixel(line);
- const RECT rc = {1, top_pixel, client_rect.right - client_rect.left - 1,
- top_pixel + line_info_.line_height};
- FillRect(dc, &rc, line_info_.brushes[status]);
-
- // Calculate and display contents/description sections as follows:
- // * 2 px top margin, bottom margin is handled by line_height.
- const int y = rc.top + 2;
-
- // * 1 char left/right margin.
- const int side_margin = line_info_.ave_char_width;
-
- // * 50% of the remaining width is initially allocated to each section, with
- // a 2 char margin followed by the star column and kStarPadding padding.
- const int content_min_x = rc.left + side_margin;
- const int description_max_x = rc.right - side_margin;
- const int mid_line = (description_max_x - content_min_x) / 2 + content_min_x;
- const int star_col_width = kStarPadding + star_->width();
- const int content_right_margin = line_info_.ave_char_width * 2;
-
- // * If this would make the content section display fewer than 40 characters,
- // the content section is increased to that minimum at the expense of the
- // description section.
- const int content_width =
- std::max(mid_line - content_min_x - content_right_margin,
- line_info_.ave_char_width * 40);
- const int description_width = description_max_x - content_min_x -
- content_width - star_col_width;
-
- // * If this would make the description section display fewer than 20
- // characters, or if there are no descriptions to display or the result is
- // the HISTORY_SEARCH shortcut, the description section is eliminated, and
- // all the available width is used for the content section.
- int star_x;
- const AutocompleteMatch& match = model_->result().match_at(line);
- if ((description_width < (line_info_.ave_char_width * 20)) ||
- all_descriptions_empty ||
- (match.type == AutocompleteMatch::OPEN_HISTORY_PAGE)) {
- star_x = description_max_x - star_col_width + kStarPadding;
- DrawMatchFragments(dc, match.contents, match.contents_class, content_min_x,
- y, star_x - kStarPadding, status);
- } else {
- star_x = description_max_x - description_width - star_col_width;
- DrawMatchFragments(dc, match.contents, match.contents_class, content_min_x,
- y, content_min_x + content_width, status);
- DrawMatchFragments(dc, match.description, match.description_class,
- description_max_x - description_width, y,
- description_max_x, status);
- }
- if (starred)
- DrawStar(dc, star_x,
- (line_info_.line_height - star_->height()) / 2 + top_pixel);
-}
-
-void AutocompletePopupViewWin::DrawStar(HDC dc, int x, int y) const {
- gfx::Canvas canvas(star_->width(), star_->height(), false);
- // Make the background completely transparent.
- canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
- canvas.DrawBitmapInt(*star_, 0, 0);
- canvas.getTopPlatformDevice().drawToHDC(
- dc, mirroring_context_->GetLeft(x, x + star_->width()), y, NULL);
-}
-
-// static
-AutocompletePopupView* AutocompletePopupView::CreatePopupView(
- const gfx::Font& font,
- AutocompleteEditViewWin* edit_view,
- AutocompleteEditModel* edit_model,
- Profile* profile,
- AutocompletePopupPositioner* popup_positioner) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableOmnibox2))
- return new AutocompletePopupViewWin(font, edit_view, edit_model, profile);
- return new AutocompletePopupContentsView(font, edit_view, edit_model,
- profile, popup_positioner);
-}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_win.h b/chrome/browser/autocomplete/autocomplete_popup_view_win.h
deleted file mode 100644
index fbab53a..0000000
--- a/chrome/browser/autocomplete/autocomplete_popup_view_win.h
+++ /dev/null
@@ -1,210 +0,0 @@
-// Copyright (c) 2006-2008 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.
-
-#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_WIN_H_
-#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_WIN_H_
-
-#include <atlbase.h>
-#include <atlapp.h>
-#include <atlcrack.h>
-#include <atlmisc.h>
-
-#include <string>
-
-#include "app/gfx/font.h"
-#include "base/scoped_ptr.h"
-#include "base/win_util.h"
-#include "chrome/browser/autocomplete/autocomplete.h"
-#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
-#include "webkit/glue/window_open_disposition.h"
-
-class AutocompletePopupModel;
-class AutocompleteEditModel;
-class AutocompleteEditViewWin;
-class Profile;
-class SkBitmap;
-
-#define AUTOCOMPLETEPOPUPVIEW_CLASSNAME L"Chrome_AutocompletePopupView"
-
-// This class implements a popup window used to display autocomplete results.
-class AutocompletePopupViewWin
- : public CWindowImpl<AutocompletePopupViewWin, CWindow, CControlWinTraits>,
- public AutocompletePopupView {
- public:
- DECLARE_WND_CLASS_EX(AUTOCOMPLETEPOPUPVIEW_CLASSNAME,
- ((win_util::GetWinVersion() < win_util::WINVERSION_XP) ?
- 0 : CS_DROPSHADOW), COLOR_WINDOW)
-
- BEGIN_MSG_MAP(AutocompletePopupViewWin)
- MSG_WM_ERASEBKGND(OnEraseBkgnd)
- MSG_WM_LBUTTONDOWN(OnLButtonDown)
- MSG_WM_MBUTTONDOWN(OnMButtonDown)
- MSG_WM_LBUTTONUP(OnLButtonUp)
- MSG_WM_MBUTTONUP(OnMButtonUp)
- MSG_WM_MOUSEACTIVATE(OnMouseActivate)
- MSG_WM_MOUSELEAVE(OnMouseLeave)
- MSG_WM_MOUSEMOVE(OnMouseMove)
- MSG_WM_PAINT(OnPaint)
- END_MSG_MAP()
-
- AutocompletePopupViewWin(const gfx::Font& font,
- AutocompleteEditViewWin* edit_view,
- AutocompleteEditModel* edit_model,
- Profile* profile);
-
- // Returns true if the popup is currently open.
- virtual bool IsOpen() const { return m_hWnd != NULL; }
-
- // Invalidates one line of the autocomplete popup.
- virtual void InvalidateLine(size_t line);
-
- // Redraws the popup window to match any changes in the result set; this may
- // mean opening or closing the window.
- virtual void UpdatePopupAppearance();
-
- // Called by the model when hover is enabled or disabled.
- virtual void OnHoverEnabledOrDisabled(bool disabled);
-
- virtual void PaintUpdatesNow() { UpdateWindow(); }
-
- virtual AutocompletePopupModel* GetModel() { return model_.get(); }
-
- private:
- class MirroringContext;
-
- // Caches GDI objects and information for drawing.
- struct DrawLineInfo {
- enum LineStatus {
- NORMAL = 0,
- HOVERED,
- SELECTED,
- MAX_STATUS_ENTRIES
- };
-
- explicit DrawLineInfo(const gfx::Font& font);
- ~DrawLineInfo();
-
- static COLORREF AlphaBlend(COLORREF foreground,
- COLORREF background,
- BYTE alpha);
-
- static const wchar_t ellipsis_str[];
-
- gfx::Font regular_font; // Fonts used for rendering AutocompleteMatches.
- gfx::Font bold_font;
- int font_height; // Height (in pixels) of a line of text w/o
- // padding.
- int line_height; // Height (in pixels) of a line of text w/padding.
- int ave_char_width; // Width (in pixels) of an average character of
- // the regular font.
- int ellipsis_width; // Width (in pixels) of the ellipsis_str.
-
- // colors
- COLORREF background_colors[MAX_STATUS_ENTRIES];
- COLORREF text_colors[MAX_STATUS_ENTRIES];
- COLORREF url_colors[MAX_STATUS_ENTRIES];
-
- // brushes
- HBRUSH brushes[MAX_STATUS_ENTRIES];
-
- private:
- static double LuminosityContrast(COLORREF color1, COLORREF color2);
- static double Luminosity(COLORREF color);
- };
-
- // message handlers
- LRESULT OnEraseBkgnd(HDC hdc) {
- // We do all needed erasing ourselves in OnPaint, so the only thing that
- // WM_ERASEBKGND will do is cause flicker. Disable it by just returning
- // nonzero here ("erase completed") without doing anything.
- return 1;
- }
- void OnLButtonDown(UINT keys, const CPoint& point);
- void OnMButtonDown(UINT keys, const CPoint& point);
- void OnLButtonUp(UINT keys, const CPoint& point);
- void OnMButtonUp(UINT keys, const CPoint& point);
- LRESULT OnMouseActivate(HWND window, UINT hit_test, UINT mouse_message);
- void OnMouseLeave();
- void OnMouseMove(UINT keys, const CPoint& point);
- void OnPaint(HDC hdc);
-
- // Called by On*ButtonUp() to do the actual work of handling a button
- // release. Opens the item at the given coordinate, using the supplied
- // disposition.
- void OnButtonUp(const CPoint& point, WindowOpenDisposition disposition);
-
- // Gives the topmost y coordinate within |line|, which should be within the
- // range of valid lines.
- int LineTopPixel(size_t line) const;
-
- // Converts the given y-coordinate to a line. Due to drawing slop (window
- // borders, etc.), |y| might be within the window but outside the range of
- // pixels which correspond to lines; in this case the result will be clamped,
- // i.e., the top and bottom lines will be treated as extending to the top and
- // bottom edges of the window, respectively.
- size_t PixelToLine(int y) const;
-
- // Draws a light border around the inside of the window with the given client
- // rectangle and DC.
- void DrawBorder(const RECT& rc, HDC dc);
-
- // Draws a single run of text with a particular style. Handles both LTR and
- // RTL text as well as eliding. Returns the width, in pixels, of the string
- // as it was actually displayed.
- int DrawString(HDC dc,
- int x,
- int y,
- int max_x,
- const wchar_t* text,
- int length,
- int style,
- const DrawLineInfo::LineStatus status,
- const MirroringContext* context,
- bool text_direction_is_rtl) const;
-
- // Draws a string from the autocomplete controller which can have specially
- // marked "match" portions.
- void DrawMatchFragments(HDC dc,
- const std::wstring& text,
- const ACMatchClassifications& classifications,
- int x,
- int y,
- int max_x,
- DrawLineInfo::LineStatus status) const;
-
- // Draws one line of the text in the box.
- void DrawEntry(HDC dc,
- const RECT& client_rect,
- size_t line,
- DrawLineInfo::LineStatus status,
- bool all_descriptions_empty,
- bool starred) const;
-
- // Draws the star at the specified location
- void DrawStar(HDC dc, int x, int y) const;
-
- scoped_ptr<AutocompletePopupModel> model_;
-
- AutocompleteEditViewWin* edit_view_;
-
- // Cached GDI information for drawing.
- DrawLineInfo line_info_;
-
- // Bitmap for the star. This is owned by the ResourceBundle.
- SkBitmap* star_;
-
- // A context used for mirroring regions.
- scoped_ptr<MirroringContext> mirroring_context_;
-
- // When hovered_line_ is kNoMatch, this holds the screen coordinates of the
- // mouse position when hover tracking was turned off. If the mouse moves to a
- // point over the popup that has different coordinates, hover tracking will be
- // re-enabled. When hovered_line_ is a valid line, the value here is
- // out-of-date and should be ignored.
- CPoint last_hover_coordinates_;
-
- DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewWin);
-};
-
-#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_WIN_H_
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index d08b5b6..5c9931c 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/autocomplete/search_provider.h"
#include "app/l10n_util.h"
-#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
@@ -15,7 +14,6 @@
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url_model.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/json_value_serializer.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -670,75 +668,50 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string,
std::vector<size_t> content_param_offsets;
const TemplateURL& provider = is_keyword ? providers_.keyword_provider() :
providers_.default_provider();
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableOmnibox2)) {
- match.contents.assign(l10n_util::GetStringF(
- IDS_AUTOCOMPLETE_SEARCH_CONTENTS,
- provider.short_name(),
- query_string,
- &content_param_offsets));
- if (content_param_offsets.size() == 2) {
- AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1],
- query_string.length(),
- match.contents.length(),
- ACMatchClassification::NONE,
- &match.contents_class);
+ // We do intra-string highlighting for suggestions - the suggested segment
+ // will be highlighted, e.g. for input_text = "you" the suggestion may be
+ // "youtube", so we'll bold the "tube" section: you*tube*.
+ if (input_text != query_string) {
+ match.contents.assign(query_string);
+ size_t input_position = match.contents.find(input_text);
+ if (input_position == std::wstring::npos) {
+ // The input text is not a substring of the query string, e.g. input
+ // text is "slasdot" and the query string is "slashdot", so we bold the
+ // whole thing.
+ match.contents_class.push_back(
+ ACMatchClassification(0, ACMatchClassification::MATCH));
} else {
- // |content_param_offsets| should only not be 2 if:
- // (a) A translator screws up
- // (b) The strings have been changed and we haven't been rebuilt properly
- // (c) Some sort of crazy installer error/DLL version mismatch problem
- // that gets the wrong data out of the locale DLL?
- // While none of these are supposed to happen, we've seen this get hit in
- // the wild, so avoid the vector access in the conditional arm above,
- // which will crash.
- NOTREACHED();
- }
- } else {
- // We do intra-string highlighting for suggestions - the suggested segment
- // will be highlighted, e.g. for input_text = "you" the suggestion may be
- // "youtube", so we'll bold the "tube" section: you*tube*.
- if (input_text != query_string) {
- match.contents.assign(query_string);
- size_t input_position = match.contents.find(input_text);
- if (input_position == std::wstring::npos) {
- // The input text is not a substring of the query string, e.g. input
- // text is "slasdot" and the query string is "slashdot", so we bold the
- // whole thing.
- match.contents_class.push_back(
- ACMatchClassification(0, ACMatchClassification::MATCH));
- } else {
- // TODO(beng): ACMatchClassification::MATCH now seems to just mean
- // "bold" this. Consider modifying the terminology.
- // We don't iterate over the string here annotating all matches because
- // it looks odd to have every occurrence of a substring that may be as
- // short as a single character highlighted in a query suggestion result,
- // e.g. for input text "s" and query string "southwest airlines", it
- // looks odd if both the first and last s are highlighted.
- if (input_position != 0) {
- match.contents_class.push_back(
- ACMatchClassification(0, ACMatchClassification::NONE));
- }
+ // TODO(beng): ACMatchClassification::MATCH now seems to just mean
+ // "bold" this. Consider modifying the terminology.
+ // We don't iterate over the string here annotating all matches because
+ // it looks odd to have every occurrence of a substring that may be as
+ // short as a single character highlighted in a query suggestion result,
+ // e.g. for input text "s" and query string "southwest airlines", it
+ // looks odd if both the first and last s are highlighted.
+ if (input_position != 0) {
match.contents_class.push_back(
- ACMatchClassification(input_position, ACMatchClassification::DIM));
- size_t next_fragment_position = input_position + input_text.length();
- if (next_fragment_position < query_string.length()) {
- match.contents_class.push_back(
- ACMatchClassification(next_fragment_position,
- ACMatchClassification::NONE));
- }
+ ACMatchClassification(0, ACMatchClassification::NONE));
}
- } else {
- // Otherwise, we're dealing with the "default search" result which has no
- // completion, but has the search provider name as the description.
- match.contents.assign(query_string);
match.contents_class.push_back(
- ACMatchClassification(0, ACMatchClassification::NONE));
- match.description.assign(l10n_util::GetStringF(
- IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION,
- provider.short_name()));
- match.description_class.push_back(
- ACMatchClassification(0, ACMatchClassification::DIM));
+ ACMatchClassification(input_position, ACMatchClassification::DIM));
+ size_t next_fragment_position = input_position + input_text.length();
+ if (next_fragment_position < query_string.length()) {
+ match.contents_class.push_back(
+ ACMatchClassification(next_fragment_position,
+ ACMatchClassification::NONE));
+ }
}
+ } else {
+ // Otherwise, we're dealing with the "default search" result which has no
+ // completion, but has the search provider name as the description.
+ match.contents.assign(query_string);
+ match.contents_class.push_back(
+ ACMatchClassification(0, ACMatchClassification::NONE));
+ match.description.assign(l10n_util::GetStringF(
+ IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION,
+ provider.short_name()));
+ match.description_class.push_back(
+ ACMatchClassification(0, ACMatchClassification::DIM));
}
// When the user forced a query, we need to make sure all the fill_into_edit
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index 8f30703..32691a02 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -4,10 +4,6 @@
#include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h"
-#include <objidl.h>
-#include <commctrl.h>
-#include <dwmapi.h>
-
#include "app/gfx/canvas.h"
#include "app/gfx/color_utils.h"
#include "app/gfx/insets.h"
@@ -15,18 +11,25 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "app/theme_provider.h"
-#include "app/win_util.h"
#include "base/compiler_specific.h"
-#include "chrome/browser/autocomplete/autocomplete_edit_view_win.h"
+#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
-#include "chrome/browser/views/autocomplete/autocomplete_popup_win.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/icu38/public/common/unicode/ubidi.h"
#include "views/widget/widget.h"
+#if defined(OS_WIN)
+#include <objidl.h>
+#include <commctrl.h>
+#include <dwmapi.h>
+
+#include "app/win_util.h"
+#endif
+
// Colors for various components of the view.
+#if defined(OS_WIN)
static const SkColor kBackgroundColor =
color_utils::GetSysSkColor(COLOR_WINDOW);
static const SkColor kSelectedBackgroundColor =
@@ -41,6 +44,16 @@ static const SkColor kDimTextColor =
color_utils::GetSysSkColor(COLOR_GRAYTEXT);
static const SkColor kSelectedDimTextColor =
color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
+#else
+// TODO(beng): source from theme provider.
+static const SkColor kBackgroundColor = SK_ColorWHITE;
+static const SkColor kSelectedBackgroundColor = SK_ColorBLUE;
+static const SkColor kHoverBackgroundColor = SK_ColorCYAN;
+static const SkColor kTextColor = SK_ColorBLACK;
+static const SkColor kSelectedTextColor = SK_ColorWHITE;
+static const SkColor kDimTextColor = SK_ColorGRAY;
+static const SkColor kSelectedDimTextColor = SK_ColorWHITE;
+#endif
static const SkColor kStandardURLColor = SkColorSetRGB(0, 0x80, 0);
static const SkColor kHighlightURLColor = SkColorSetRGB(0xD0, 0xFF, 0xD0);
static const int kGlassPopupTransparency = 240;
@@ -657,11 +670,15 @@ void PopupBorder::InitClass() {
AutocompletePopupContentsView::AutocompletePopupContentsView(
const gfx::Font& font,
- AutocompleteEditViewWin* edit_view,
+ AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
AutocompletePopupPositioner* popup_positioner)
+#if defined(OS_WIN)
: popup_(new AutocompletePopupWin(this)),
+#else
+ : popup_(new AutocompletePopupGtk(this)),
+#endif
model_(new AutocompletePopupModel(this, edit_model, profile)),
edit_view_(edit_view),
popup_positioner_(popup_positioner),
@@ -690,7 +707,7 @@ gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const {
// AutocompletePopupContentsView, AutocompletePopupView overrides:
bool AutocompletePopupContentsView::IsOpen() const {
- return popup_->IsWindow() && popup_->IsVisible();
+ return popup_->IsOpen();
}
void AutocompletePopupContentsView::InvalidateLine(size_t line) {
@@ -700,7 +717,7 @@ void AutocompletePopupContentsView::InvalidateLine(size_t line) {
void AutocompletePopupContentsView::UpdatePopupAppearance() {
if (model_->result().empty()) {
// No matches, close any existing popup.
- if (popup_->IsWindow()) {
+ if (popup_->IsCreated()) {
size_animation_.Stop();
popup_->Hide();
}
@@ -739,7 +756,7 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() {
size_animation_.Reset();
target_bounds_ = new_target_bounds;
- if (!popup_->IsWindow()) {
+ if (!popup_->IsCreated()) {
// If we've never been shown, we need to create the window.
popup_->Init(edit_view_, this);
} else {
@@ -897,6 +914,7 @@ void AutocompletePopupContentsView::MakeContentsPath(
}
void AutocompletePopupContentsView::UpdateBlurRegion() {
+#if defined(OS_WIN)
// We only support background blurring on Vista with Aero-Glass enabled.
if (!win_util::ShouldUseVistaFrame() || !GetWidget())
return;
@@ -920,6 +938,7 @@ void AutocompletePopupContentsView::UpdateBlurRegion() {
popup_region.Set(contents_path.CreateHRGN());
bb.hRgnBlur = popup_region.Get();
DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb);
+#endif
}
void AutocompletePopupContentsView::MakeCanvasTransparent(
@@ -934,3 +953,14 @@ void AutocompletePopupContentsView::MakeCanvasTransparent(
canvas->FillRectInt(0, 0, canvas->getDevice()->width(),
canvas->getDevice()->height(), paint);
}
+
+// static
+AutocompletePopupView* AutocompletePopupView::CreatePopupView(
+ const gfx::Font& font,
+ AutocompleteEditView* edit_view,
+ AutocompleteEditModel* edit_model,
+ Profile* profile,
+ AutocompletePopupPositioner* popup_positioner) {
+ return new AutocompletePopupContentsView(font, edit_view, edit_model,
+ profile, popup_positioner);
+}
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
index a86914d..469ed33 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
@@ -10,15 +10,17 @@
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
+#include "views/view.h"
+#include "webkit/glue/window_open_disposition.h"
+
#if defined(OS_WIN)
#include "chrome/browser/views/autocomplete/autocomplete_popup_win.h"
+#else
+#include "chrome/browser/views/autocomplete/autocomplete_popup_gtk.h"
#endif
-#include "views/view.h"
-#include "webkit/glue/window_open_disposition.h"
class AutocompleteEditModel;
class AutocompleteEditViewWin;
-class AutocompletePopupWin;
class Profile;
// An interface implemented by an object that provides data to populate
@@ -46,7 +48,7 @@ class AutocompletePopupContentsView : public views::View,
public AnimationDelegate {
public:
AutocompletePopupContentsView(const gfx::Font& font,
- AutocompleteEditViewWin* edit_view,
+ AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
AutocompletePopupPositioner* popup_positioner);
@@ -97,13 +99,15 @@ class AutocompletePopupContentsView : public views::View,
#if defined(OS_WIN)
// The popup that contains this view.
scoped_ptr<AutocompletePopupWin> popup_;
+#else
+ scoped_ptr<AutocompletePopupGtk> popup_;
#endif
// The provider of our result set.
scoped_ptr<AutocompletePopupModel> model_;
// The edit view that invokes us.
- AutocompleteEditViewWin* edit_view_;
+ AutocompleteEditView* edit_view_;
// An object that tells the popup how to position itself.
AutocompletePopupPositioner* popup_positioner_;
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc b/chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc
new file mode 100644
index 0000000..0905546
--- /dev/null
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_gtk.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2009 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/views/autocomplete/autocomplete_popup_gtk.h"
+
+#include "app/gfx/insets.h"
+#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
+#include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// AutocompletePopupGtk, public:
+
+AutocompletePopupGtk::AutocompletePopupGtk(
+ AutocompletePopupContentsView* contents)
+ : WidgetGtk(WidgetGtk::TYPE_POPUP),
+ contents_(contents) {
+ set_delete_on_destroy(false);
+}
+
+AutocompletePopupGtk::~AutocompletePopupGtk() {
+}
+
+void AutocompletePopupGtk::Init(AutocompleteEditView* edit_view,
+ views::View* contents) {
+ MakeTransparent();
+ // Create the popup
+ WidgetGtk::Init(gtk_widget_get_parent(edit_view->GetNativeView()),
+ contents_->GetPopupBounds());
+ // The contents is owned by the LocationBarView.
+ contents_->SetParentOwned(false);
+ SetContentsView(contents_);
+}
+
+void AutocompletePopupGtk::Show() {
+ // Move the popup to the place appropriate for the window's current position -
+ // it may have been moved since it was last shown.
+ SetBounds(contents_->GetPopupBounds());
+ if (!IsVisible())
+ WidgetGtk::Show();
+}
+
+bool AutocompletePopupGtk::IsOpen() const {
+ return IsCreated() && IsVisible();
+}
+
+bool AutocompletePopupGtk::IsCreated() const {
+ return GTK_IS_WIDGET(GetNativeView());
+}
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_gtk.h b/chrome/browser/views/autocomplete/autocomplete_popup_gtk.h
new file mode 100644
index 0000000..3ae2625
--- /dev/null
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_gtk.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_GTK_H_
+#define CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_GTK_H_
+
+#include "views/widget/widget_gtk.h"
+
+class AutocompleteEditView;
+class AutocompletePopupContentsView;
+
+class AutocompletePopupGtk : public views::WidgetGtk {
+ public:
+ explicit AutocompletePopupGtk(AutocompletePopupContentsView* contents);
+ virtual ~AutocompletePopupGtk();
+
+ // Creates the popup and shows it for the first time. |edit_view| is the edit
+ // that created us.
+ void Init(AutocompleteEditView* edit_view, views::View* contents);
+
+ // Shows the popup and moves it to the right position.
+ void Show();
+
+ // Returns true if the popup is open.
+ bool IsOpen() const;
+
+ // Returns true if the popup has been created.
+ bool IsCreated() const;
+
+ private:
+ AutocompletePopupContentsView* contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutocompletePopupGtk);
+};
+
+#endif // #ifndef CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_GTK_H_
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_win.cc b/chrome/browser/views/autocomplete/autocomplete_popup_win.cc
index e28e0a5..3834a861b 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_win.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_win.cc
@@ -24,10 +24,10 @@ AutocompletePopupWin::AutocompletePopupWin(
AutocompletePopupWin::~AutocompletePopupWin() {
}
-void AutocompletePopupWin::Init(AutocompleteEditViewWin* edit_view,
+void AutocompletePopupWin::Init(AutocompleteEditView* edit_view,
views::View* contents) {
// Create the popup
- WidgetWin::Init(edit_view->parent_view()->GetWidget()->GetNativeView(),
+ WidgetWin::Init(GetAncestor(edit_view->GetNativeView(), GA_ROOT),
contents_->GetPopupBounds());
// The contents is owned by the LocationBarView.
contents_->SetParentOwned(false);
@@ -38,7 +38,7 @@ void AutocompletePopupWin::Init(AutocompleteEditViewWin* edit_view,
// Otherwise, show this popup window under top-most windows.
// TODO(hbono): http://b/1111369 if we exclude this popup window from the
// display area of IME windows, this workaround becomes unnecessary.
- HWND ime_window = ImmGetDefaultIMEWnd(edit_view->m_hWnd);
+ HWND ime_window = ImmGetDefaultIMEWnd(edit_view->GetNativeView());
SetWindowPos(ime_window ? ime_window : HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
}
@@ -51,6 +51,14 @@ void AutocompletePopupWin::Show() {
WidgetWin::Show();
}
+bool AutocompletePopupWin::IsOpen() const {
+ return IsCreated() && IsVisible();
+}
+
+bool AutocompletePopupWin::IsCreated() const {
+ return !!IsWindow();
+}
+
////////////////////////////////////////////////////////////////////////////////
// AutocompletePopupWin, WidgetWin overrides:
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_win.h b/chrome/browser/views/autocomplete/autocomplete_popup_win.h
index d77ba7b..8e33f56 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_win.h
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_win.h
@@ -7,7 +7,7 @@
#include "views/widget/widget_win.h"
-class AutocompleteEditViewWin;
+class AutocompleteEditView;
class AutocompletePopupContentsView;
class AutocompletePopupWin : public views::WidgetWin {
@@ -17,11 +17,17 @@ class AutocompletePopupWin : public views::WidgetWin {
// Creates the popup and shows it for the first time. |edit_view| is the edit
// that created us.
- void Init(AutocompleteEditViewWin* edit_view, views::View* contents);
+ void Init(AutocompleteEditView* edit_view, views::View* contents);
// Shows the popup and moves it to the right position.
void Show();
+ // Returns true if the popup is open.
+ bool IsOpen() const;
+
+ // Returns true if the popup has been created.
+ bool IsCreated() const;
+
protected:
// Overridden from WidgetWin:
virtual LRESULT OnMouseActivate(HWND window,
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index d20f6f6..67391ed 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -606,8 +606,6 @@
'browser/autocomplete/autocomplete_popup_view_gtk.h',
'browser/autocomplete/autocomplete_popup_view_mac.h',
'browser/autocomplete/autocomplete_popup_view_mac.mm',
- 'browser/autocomplete/autocomplete_popup_view_win.cc',
- 'browser/autocomplete/autocomplete_popup_view_win.h',
'browser/autocomplete/history_contents_provider.cc',
'browser/autocomplete/history_contents_provider.h',
'browser/autocomplete/history_url_provider.cc',
@@ -1644,6 +1642,8 @@
'browser/views/autocomplete/autocomplete_popup_contents_view.h',
'browser/views/autocomplete/autocomplete_popup_win.cc',
'browser/views/autocomplete/autocomplete_popup_win.h',
+ 'browser/views/autocomplete/autocomplete_popup_gtk.cc',
+ 'browser/views/autocomplete/autocomplete_popup_gtk.h',
'browser/views/blocked_popup_container_view_win.cc',
'browser/views/blocked_popup_container_view_win.h',
'browser/views/bookmark_bar_view.cc',
@@ -1957,6 +1957,8 @@
['OS=="linux" and toolkit_views==0', {
'sources!': [
'browser/bookmarks/bookmark_drop_info.cc',
+ 'browser/views/autocomplete/autocomplete_popup_gtk.cc',
+ 'browser/views/autocomplete/autocomplete_popup_gtk.h'
],
}],
['OS=="mac"', {
@@ -2115,6 +2117,10 @@
['include', '^browser/dock_info.cc'],
['include', '^browser/dock_info.h'],
['include', '^browser/extensions/'],
+ ['include', '^browser/views/autocomplete/autocomplete_popup_contents_view.cc'],
+ ['include', '^browser/views/autocomplete/autocomplete_popup_contents_view.h'],
+ ['include', '^browser/views/autocomplete/autocomplete_popup_gtk.cc'],
+ ['include', '^browser/views/autocomplete/autocomplete_popup_gtk.h'],
['include', '^browser/views/bookmark_bar_view.cc'],
['include', '^browser/views/bookmark_bar_view.h'],
['include', '^browser/views/bookmark_context_menu.cc'],
@@ -2244,6 +2250,8 @@
['include', '^browser/gtk/menu_gtk.h'],
# Other excluded stuff.
+ ['exclude', '^browser/autocomplete/autocomplete_popup_view_gtk.cc'],
+ ['exclude', '^browser/autocomplete/autocomplete_popup_view_gtk.h'],
['exclude', '^browser/browser_theme_provider_gtk.cc'],
['exclude', '^browser/extensions/external_registry_extension_provider_win.cc'],
['exclude', '^browser/tab_contents/tab_contents_view_gtk.cc'],
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index e0a35a6..6b8c8a2 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -449,8 +449,6 @@ const wchar_t kAutoSpellCorrect[] = L"auto-spell-correct";
// Enables StatsTable, logging statistics to a global named shared memory table.
const wchar_t kEnableStatsTable[] = L"enable-stats-table";
-// Disables the Omnibox2 popup and functionality.
-const wchar_t kDisableOmnibox2[] = L"disable-omnibox2";
// Replaces the audio IPC layer for <audio> and <video> with a mock audio
// device, useful when using remote desktop or machines without sound cards.
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index ee04a2c..4794b71 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -171,8 +171,6 @@ extern const wchar_t kEnableStatsTable[];
extern const wchar_t kAutoSpellCorrect[];
-extern const wchar_t kDisableOmnibox2[];
-
extern const wchar_t kDisableAudio[];
extern const wchar_t kSimpleDataSource[];