summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/compact_location_bar.cc3
-rw-r--r--chrome/browser/views/dropdown_bar_host.cc190
-rw-r--r--chrome/browser/views/dropdown_bar_host.h178
-rw-r--r--chrome/browser/views/dropdown_bar_host_gtk.cc36
-rw-r--r--chrome/browser/views/dropdown_bar_host_win.cc52
-rw-r--r--chrome/browser/views/dropdown_bar_view.h53
-rw-r--r--chrome/browser/views/find_bar_host.cc231
-rw-r--r--chrome/browser/views/find_bar_host.h119
-rw-r--r--chrome/browser/views/find_bar_host_browsertest.cc259
-rw-r--r--chrome/browser/views/find_bar_host_gtk.cc39
-rw-r--r--chrome/browser/views/find_bar_host_win.cc43
-rw-r--r--chrome/browser/views/find_bar_view.cc39
-rw-r--r--chrome/browser/views/find_bar_view.h27
-rwxr-xr-xchrome/chrome.gyp21
14 files changed, 783 insertions, 507 deletions
diff --git a/chrome/browser/chromeos/compact_location_bar.cc b/chrome/browser/chromeos/compact_location_bar.cc
index 8cd3b82..e405475 100644
--- a/chrome/browser/chromeos/compact_location_bar.cc
+++ b/chrome/browser/chromeos/compact_location_bar.cc
@@ -35,7 +35,8 @@ const int kHideTimeoutInSeconds = 2;
CompactLocationBar::CompactLocationBar(BrowserView* browser_view)
: browser_view_(browser_view),
current_contents_(NULL),
- reload_(NULL) {
+ reload_(NULL),
+ popup_(NULL) {
popup_timer_.reset(new base::OneShotTimer<CompactLocationBar>());
set_background(views::Background::CreateStandardPanelBackground());
}
diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc
new file mode 100644
index 0000000..ee647d25
--- /dev/null
+++ b/chrome/browser/views/dropdown_bar_host.cc
@@ -0,0 +1,190 @@
+// Copyright (c) 2006-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/dropdown_bar_host.h"
+
+#include "app/slide_animation.h"
+#include "base/keyboard_codes.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/view_ids.h"
+#include "chrome/browser/views/dropdown_bar_view.h"
+#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_view.h"
+#include "views/focus/external_focus_tracker.h"
+#include "views/focus/view_storage.h"
+#include "views/widget/widget.h"
+
+// static
+bool DropdownBarHost::disable_animations_during_testing_ = false;
+
+////////////////////////////////////////////////////////////////////////////////
+// DropdownBarHost, public:
+
+DropdownBarHost::DropdownBarHost(BrowserView* browser_view)
+ : browser_view_(browser_view),
+ animation_offset_(0),
+ esc_accel_target_registered_(false) {
+}
+
+void DropdownBarHost::Init(DropdownBarView* view) {
+ view_ = view;
+
+ // Initialize the host.
+ host_.reset(CreateHost());
+ host_->Init(GetNativeView(browser_view_), gfx::Rect());
+ host_->SetContentsView(view_);
+
+ // Start listening to focus changes, so we can register and unregister our
+ // own handler for Escape.
+ focus_manager_ =
+ views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView());
+ if (focus_manager_) {
+ focus_manager_->AddFocusChangeListener(this);
+ } else {
+ // In some cases (see bug http://crbug.com/17056) it seems we may not have
+ // a focus manager. Please reopen the bug if you hit this.
+ NOTREACHED();
+ }
+
+ // Start the process of animating the opening of the widget.
+ animation_.reset(new SlideAnimation(this));
+}
+
+DropdownBarHost::~DropdownBarHost() {
+ focus_manager_->RemoveFocusChangeListener(this);
+ focus_tracker_.reset(NULL);
+}
+
+void DropdownBarHost::Show() {
+ // Stores the currently focused view, and tracks focus changes so that we can
+ // restore focus when the dropdown widget is closed.
+ focus_tracker_.reset(new views::ExternalFocusTracker(view_, focus_manager_));
+
+ if (disable_animations_during_testing_) {
+ animation_->Reset(1);
+ AnimationProgressed(animation_.get());
+ } else {
+ animation_->Reset();
+ animation_->Show();
+ }
+}
+
+void DropdownBarHost::SetFocusAndSelection() {
+ view_->SetFocusAndSelection();
+}
+
+bool DropdownBarHost::IsAnimating() const {
+ return animation_->IsAnimating();
+}
+
+void DropdownBarHost::Hide(bool animate) {
+ if (animate && !disable_animations_during_testing_) {
+ animation_->Reset(1.0);
+ animation_->Hide();
+ } else {
+ host_->Hide();
+ }
+}
+
+void DropdownBarHost::StopAnimation() {
+ animation_->End();
+}
+
+bool DropdownBarHost::IsVisible() const {
+ return host_->IsVisible();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DropdownBarHost, views::FocusChangeListener implementation:
+void DropdownBarHost::FocusWillChange(views::View* focused_before,
+ views::View* focused_now) {
+ // First we need to determine if one or both of the views passed in are child
+ // views of our view.
+ bool our_view_before = focused_before && view_->IsParentOf(focused_before);
+ bool our_view_now = focused_now && view_->IsParentOf(focused_now);
+
+ // When both our_view_before and our_view_now are false, it means focus is
+ // changing hands elsewhere in the application (and we shouldn't do anything).
+ // Similarly, when both are true, focus is changing hands within the dropdown
+ // widget (and again, we should not do anything). We therefore only need to
+ // look at when we gain initial focus and when we loose it.
+ if (!our_view_before && our_view_now) {
+ // We are gaining focus from outside the dropdown widget so we must register
+ // a handler for Escape.
+ RegisterEscAccelerator();
+ } else if (our_view_before && !our_view_now) {
+ // We are losing focus to something outside our widget so we restore the
+ // original handler for Escape.
+ UnregisterEscAccelerator();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DropdownBarHost, AnimationDelegate implementation:
+
+void DropdownBarHost::AnimationProgressed(const Animation* animation) {
+ // First, we calculate how many pixels to slide the widget.
+ gfx::Size pref_size = view_->GetPreferredSize();
+ animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) *
+ pref_size.height());
+
+ // This call makes sure it appears in the right location, the size and shape
+ // is correct and that it slides in the right direction.
+ gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect());
+ SetDialogPosition(dlg_rect, false);
+
+ // Let the view know if we are animating, and at which offset to draw the
+ // edges.
+ view_->set_animation_offset(animation_offset_);
+ view_->SchedulePaint();
+}
+
+void DropdownBarHost::AnimationEnded(const Animation* animation) {
+ // Place the dropdown widget in its fully opened state.
+ animation_offset_ = 0;
+
+ if (!animation_->IsShowing()) {
+ // Animation has finished closing.
+ host_->Hide();
+ } else {
+ // Animation has finished opening.
+ }
+}
+
+void DropdownBarHost::GetThemePosition(gfx::Rect* bounds) {
+ *bounds = GetDialogPosition(gfx::Rect());
+ gfx::Rect toolbar_bounds = browser_view_->GetToolbarBounds();
+ gfx::Rect tab_strip_bounds = browser_view_->GetTabStripBounds();
+ bounds->Offset(-toolbar_bounds.x(), -tab_strip_bounds.y());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DropdownBarHost protected:
+
+void DropdownBarHost::ResetFocusTracker() {
+ focus_tracker_.reset(NULL);
+}
+
+void DropdownBarHost::GetWidgetBounds(gfx::Rect* bounds) {
+ DCHECK(bounds);
+ // The BrowserView does Layout for the components that we care about
+ // positioning relative to, so we ask it to tell us where we should go.
+ *bounds = browser_view_->GetFindBarBoundingBox();
+}
+
+void DropdownBarHost::RegisterEscAccelerator() {
+ DCHECK(!esc_accel_target_registered_);
+ views::Accelerator escape(base::VKEY_ESCAPE, false, false, false);
+ focus_manager_->RegisterAccelerator(escape, this);
+ esc_accel_target_registered_ = true;
+}
+
+void DropdownBarHost::UnregisterEscAccelerator() {
+ DCHECK(esc_accel_target_registered_);
+ views::Accelerator escape(base::VKEY_ESCAPE, false, false, false);
+ focus_manager_->UnregisterAccelerator(escape, this);
+ esc_accel_target_registered_ = false;
+}
diff --git a/chrome/browser/views/dropdown_bar_host.h b/chrome/browser/views/dropdown_bar_host.h
new file mode 100644
index 0000000..635ee18
--- /dev/null
+++ b/chrome/browser/views/dropdown_bar_host.h
@@ -0,0 +1,178 @@
+// Copyright (c) 2006-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_DROPDOWN_BAR_HOST_H_
+#define CHROME_BROWSER_VIEWS_DROPDOWN_BAR_HOST_H_
+
+#include "app/animation.h"
+#include "app/gfx/native_widget_types.h"
+#include "base/gfx/rect.h"
+#include "base/scoped_ptr.h"
+#include "chrome/common/native_web_keyboard_event.h"
+#include "views/controls/textfield/textfield.h"
+#include "views/focus/focus_manager.h"
+
+class BrowserView;
+class DropdownBarView;
+class SlideAnimation;
+class TabContents;
+
+namespace views {
+class ExternalFocusTracker;
+class View;
+class Widget;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// The DropdownBarHost implements the container widget for the UI that
+// is shown at the top of browser contents. It uses the appropriate
+// implementation from dropdown_bar_host_win.cc or dropdown_bar_host_gtk.cc to
+// draw its content and is responsible for showing, hiding, animating, closing,
+// and moving the bar if needed, for example if the widget is
+// obscuring the selection results in FindBar.
+//
+////////////////////////////////////////////////////////////////////////////////
+class DropdownBarHost : public views::AcceleratorTarget,
+ public views::FocusChangeListener,
+ public AnimationDelegate {
+ public:
+ explicit DropdownBarHost(BrowserView* browser_view);
+ virtual ~DropdownBarHost();
+
+ // Initializes the dropdown bar host with the give view.
+ void Init(DropdownBarView* view);
+
+ // Whether we are animating the position of the dropdown widget.
+ bool IsAnimating() const;
+ // Returns true if the dropdown bar view is visible, or false otherwise.
+ bool IsVisible() const;
+ // Shows the dropdown bar.
+ void Show();
+ // Hides the dropdown bar.
+ void Hide(bool animate);
+ // Selects text in the entry field and set focus.
+ void SetFocusAndSelection();
+ // Stops the animation.
+ void StopAnimation();
+
+ // Returns the rectangle representing where to position the dropdown widget.
+ virtual gfx::Rect GetDialogPosition(gfx::Rect avoid_overlapping_rect) = 0;
+
+ // Moves the widget to the provided location, moves it to top
+ // in the z-order (HWND_TOP, not HWND_TOPMOST for windows) and shows
+ // the widget (if hidden).
+ virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) = 0;
+
+ // Overridden from views::FocusChangeListener:
+ virtual void FocusWillChange(views::View* focused_before,
+ views::View* focused_now);
+
+ // Overridden from views::AcceleratorTarget:
+ virtual bool AcceleratorPressed(const views::Accelerator& accelerator) = 0;
+
+ // AnimationDelegate implementation:
+ virtual void AnimationProgressed(const Animation* animation);
+ virtual void AnimationEnded(const Animation* animation);
+
+ // Get the offset with which to paint the theme image.
+ void GetThemePosition(gfx::Rect* bounds);
+
+ // During testing we can disable animations by setting this flag to true,
+ // so that opening and closing the dropdown bar is shown instantly, instead of
+ // having to poll it while it animates to open/closed status.
+ static bool disable_animations_during_testing_;
+
+ protected:
+ // Returns the dropdown bar view.
+ DropdownBarView* view() const { return view_; }
+
+ // Returns the browser view that the dropdown belongs to.
+ BrowserView* browser_view() const { return browser_view_; }
+
+ // Returns the focus tracker.
+ views::ExternalFocusTracker* focus_tracker() const {
+ return focus_tracker_.get();
+ }
+
+ // Resets the focus tracker.
+ void ResetFocusTracker();
+
+ // The focus manager we register with to keep track of focus changes.
+ views::FocusManager* focus_manager() const { return focus_manager_; }
+
+ // Returns the host widget.
+ views::Widget* host() const { return host_.get(); }
+
+ // Returns the animation offset.
+ int animation_offset() const { return animation_offset_; }
+
+ // Retrieves the boundaries that the dropdown widget has to work with
+ // within the Chrome frame window. The resulting rectangle will be a
+ // rectangle that overlaps the bottom of the Chrome toolbar by one
+ // pixel (so we can create the illusion that the dropdown widget is
+ // part of the toolbar) and covers the page area, except that we
+ // deflate the rect width by subtracting (from both sides) the width
+ // of the toolbar and some extra pixels to account for the width of
+ // the Chrome window borders. |bounds| is relative to the browser
+ // window. If the function fails to determine the browser
+ // window/client area rectangle or the rectangle for the page area
+ // then |bounds| will be an empty rectangle.
+ void GetWidgetBounds(gfx::Rect* bounds);
+
+ // Registers this class as the handler for when Escape is pressed. We will
+ // unregister once we loose focus. See also: SetFocusChangeListener().
+ void RegisterEscAccelerator();
+
+ // When we loose focus, we unregister the handler for Escape. See
+ // also: SetFocusChangeListener().
+ void UnregisterEscAccelerator();
+
+ // Creates and returns the native Widget.
+ views::Widget* CreateHost();
+
+ // Allows implementation to tweak widget position.
+ void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw);
+
+ // Returns the native view (is a child of the window widget in gtk).
+ gfx::NativeView GetNativeView(BrowserView* browser_view);
+
+ // Returns a keyboard event suitable for fowarding.
+ NativeWebKeyboardEvent GetKeyboardEvent(
+ const TabContents* contents,
+ const views::Textfield::Keystroke& key_stroke);
+
+ private:
+ // The BrowserView that created us.
+ BrowserView* browser_view_;
+
+ // Our view, which is responsible for drawing the UI.
+ DropdownBarView* view_;
+
+ // The y position pixel offset of the widget while animating the
+ // dropdown widget.
+ int animation_offset_;
+
+ // The animation class to use when opening the Dropdown widget.
+ scoped_ptr<SlideAnimation> animation_;
+
+ // The focus manager we register with to keep track of focus changes.
+ views::FocusManager* focus_manager_;
+
+ // True if the accelerator target for Esc key is registered.
+ bool esc_accel_target_registered_;
+
+ // Tracks and stores the last focused view which is not the DropdownBarView
+ // or any of its children. Used to restore focus once the DropdownBarView is
+ // closed.
+ scoped_ptr<views::ExternalFocusTracker> focus_tracker_;
+
+ // Host is the Widget implementation that is created and maintained by the
+ // dropdown bar. It contains the DropdownBarView.
+ scoped_ptr<views::Widget> host_;
+
+ DISALLOW_COPY_AND_ASSIGN(DropdownBarHost);
+};
+
+#endif // CHROME_BROWSER_VIEWS_DROPDOWN_BAR_HOST_H_
diff --git a/chrome/browser/views/dropdown_bar_host_gtk.cc b/chrome/browser/views/dropdown_bar_host_gtk.cc
new file mode 100644
index 0000000..751d0d8
--- /dev/null
+++ b/chrome/browser/views/dropdown_bar_host_gtk.cc
@@ -0,0 +1,36 @@
+// Copyright (c) 2006-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/dropdown_bar_host.h"
+
+#include <gdk/gdkkeysyms.h>
+
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/views/frame/browser_view.h"
+#include "views/widget/widget_gtk.h"
+#include "views/controls/textfield/textfield.h"
+
+views::Widget* DropdownBarHost::CreateHost() {
+ views::WidgetGtk* host = new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
+ // We own the host.
+ host->set_delete_on_destroy(false);
+ return host;
+}
+
+void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos,
+ bool no_redraw) {
+ host_->SetBounds(new_pos);
+ host_->Show();
+}
+
+gfx::NativeView DropdownBarHost::GetNativeView(BrowserView* browser_view) {
+ return static_cast<views::WidgetGtk*>(
+ browser_view->GetWidget())->window_contents();
+}
+
+NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent(
+ const TabContents* contents,
+ const views::Textfield::Keystroke& key_stroke) {
+ return NativeWebKeyboardEvent(key_stroke.event());
+}
diff --git a/chrome/browser/views/dropdown_bar_host_win.cc b/chrome/browser/views/dropdown_bar_host_win.cc
new file mode 100644
index 0000000..e5335dd
--- /dev/null
+++ b/chrome/browser/views/dropdown_bar_host_win.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2006-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/dropdown_bar_host.h"
+
+#include "chrome/browser/find_bar_controller.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_view.h"
+#include "chrome/browser/views/frame/browser_view.h"
+#include "views/controls/scrollbar/native_scroll_bar.h"
+#include "views/widget/widget_win.h"
+
+NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent(
+ const TabContents* contents,
+ const views::Textfield::Keystroke& key_stroke) {
+ HWND hwnd = contents->GetContentNativeView();
+ return NativeWebKeyboardEvent(
+ hwnd, key_stroke.message(), key_stroke.key(), 0);
+}
+
+views::Widget* DropdownBarHost::CreateHost() {
+ views::WidgetWin* widget = new views::WidgetWin();
+ // Don't let WidgetWin manage our lifetime. We want our lifetime to
+ // coincide with TabContents.
+ widget->set_delete_on_destroy(false);
+ widget->set_window_style(WS_CHILD | WS_CLIPCHILDREN);
+ widget->set_window_ex_style(WS_EX_TOPMOST);
+
+ return widget;
+}
+
+void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos,
+ bool no_redraw) {
+ gfx::Rect window_rect;
+ host_->GetBounds(&window_rect, true);
+ DWORD swp_flags = SWP_NOOWNERZORDER;
+ if (!window_rect.IsEmpty())
+ swp_flags |= SWP_NOSIZE;
+ if (no_redraw)
+ swp_flags |= SWP_NOREDRAW;
+ if (!host_->IsVisible())
+ swp_flags |= SWP_SHOWWINDOW;
+
+ ::SetWindowPos(host_->GetNativeView(), HWND_TOP, new_pos.x(), new_pos.y(),
+ new_pos.width(), new_pos.height(), swp_flags);
+}
+
+gfx::NativeView DropdownBarHost::GetNativeView(BrowserView* browser_view) {
+ return browser_view->GetWidget()->GetNativeView();
+}
diff --git a/chrome/browser/views/dropdown_bar_view.h b/chrome/browser/views/dropdown_bar_view.h
new file mode 100644
index 0000000..7fcc319
--- /dev/null
+++ b/chrome/browser/views/dropdown_bar_view.h
@@ -0,0 +1,53 @@
+// 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_DROPDOWN_BAR_VIEW_H_
+#define CHROME_BROWSER_VIEWS_DROPDOWN_BAR_VIEW_H_
+
+#include "views/view.h"
+
+class DropdownBarHost;
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// The DropdownBarView is an abstract view to draw the UI controls of the
+// DropdownBarHost.
+//
+////////////////////////////////////////////////////////////////////////////////
+class DropdownBarView : public views::View {
+ public:
+ explicit DropdownBarView(DropdownBarHost* host)
+ : host_(host),
+ animation_offset_(0) {
+ }
+ virtual ~DropdownBarView() {}
+
+ // Claims focus for the text field and selects its contents.
+ virtual void SetFocusAndSelection() = 0;
+
+ // Updates the view to let it know where the host is clipping the
+ // dropdown widget (while animating the opening or closing of the widget).
+ void set_animation_offset(int offset) { animation_offset_ = offset; }
+
+ // Returns the offset used while animating.
+ int animation_offset() const { return animation_offset_; }
+
+ protected:
+ // Returns the DropdownBarHost that manages this view.
+ DropdownBarHost* host() const { return host_; }
+
+ private:
+ // The dropdown bar host that controls this view.
+ DropdownBarHost* host_;
+
+ // While animating, the host clips the widget and draws only the bottom
+ // part of it. The view needs to know the pixel offset at which we are drawing
+ // the widget so that we can draw the curved edges that attach to the toolbar
+ // in the right location.
+ int animation_offset_;
+
+ DISALLOW_COPY_AND_ASSIGN(DropdownBarView);
+};
+
+#endif // CHROME_BROWSER_VIEWS_DROPDOW_BAR_VIEW_H_
diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc
index 1f53cd2..9b2cda5 100644
--- a/chrome/browser/views/find_bar_host.cc
+++ b/chrome/browser/views/find_bar_host.cc
@@ -21,9 +21,7 @@
#include "views/focus/view_storage.h"
#include "views/controls/scrollbar/native_scroll_bar.h"
#include "views/widget/root_view.h"
-
-// static
-bool FindBarHost::disable_animations_during_testing_ = false;
+#include "views/widget/widget.h"
using gfx::Path;
@@ -40,89 +38,46 @@ FindBar* CreateFindBar(BrowserView* browser_view) {
// FindBarHost, public:
FindBarHost::FindBarHost(BrowserView* browser_view)
- : browser_view_(browser_view),
- find_dialog_animation_offset_(0),
- esc_accel_target_registered_(false),
+ : DropdownBarHost(browser_view),
find_bar_controller_(NULL) {
- view_ = new FindBarView(this);
-
- // Initialize the host.
- host_.reset(CreateHost());
- host_->Init(GetNativeView(browser_view), gfx::Rect());
- host_->SetContentsView(view_);
-
- // Start listening to focus changes, so we can register and unregister our
- // own handler for Escape.
- focus_manager_ =
- views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView());
- if (focus_manager_) {
- focus_manager_->AddFocusChangeListener(this);
- } else {
- // In some cases (see bug http://crbug.com/17056) it seems we may not have
- // a focus manager. Please reopen the bug if you hit this.
- NOTREACHED();
- }
-
- // Start the process of animating the opening of the window.
- animation_.reset(new SlideAnimation(this));
+ Init(new FindBarView(this));
}
FindBarHost::~FindBarHost() {
- focus_manager_->RemoveFocusChangeListener(this);
- focus_tracker_.reset(NULL);
}
void FindBarHost::Show() {
- // Stores the currently focused view, and tracks focus changes so that we can
- // restore focus when the find box is closed.
- focus_tracker_.reset(new views::ExternalFocusTracker(view_, focus_manager_));
-
- if (disable_animations_during_testing_) {
- animation_->Reset(1);
- MoveWindowIfNecessary(gfx::Rect(), true);
- } else {
- animation_->Reset();
- animation_->Show();
- }
+ DropdownBarHost::Show();
}
void FindBarHost::SetFocusAndSelection() {
- view_->SetFocusAndSelection();
-}
-
-bool FindBarHost::IsAnimating() {
- return animation_->IsAnimating();
+ DropdownBarHost::SetFocusAndSelection();
}
void FindBarHost::Hide(bool animate) {
- if (animate && !disable_animations_during_testing_) {
- animation_->Reset(1.0);
- animation_->Hide();
- } else {
- host_->Hide();
- }
+ DropdownBarHost::Hide(animate);
}
void FindBarHost::ClearResults(const FindNotificationDetails& results) {
- view_->UpdateForResult(results, string16());
+ find_bar_view()->UpdateForResult(results, string16());
}
void FindBarHost::StopAnimation() {
- animation_->End();
+ DropdownBarHost::StopAnimation();
}
void FindBarHost::SetFindText(const string16& find_text) {
- view_->SetFindText(find_text);
+ find_bar_view()->SetFindText(find_text);
}
bool FindBarHost::IsFindBarVisible() {
- return host_->IsVisible();
+ return DropdownBarHost::IsVisible();
}
void FindBarHost::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
- bool no_redraw) {
+ bool no_redraw) {
// We only move the window if one is active for the current TabContents. If we
- // don't check this, then SetDialogPosition below will end up making the Find
+ // don't check this, then SetWidgetPosition below will end up making the Find
// Bar visible.
if (!find_bar_controller_->tab_contents() ||
!find_bar_controller_->tab_contents()->find_ui_active()) {
@@ -133,37 +88,7 @@ void FindBarHost::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
SetDialogPosition(new_pos, no_redraw);
// May need to redraw our frame to accommodate bookmark bar styles.
- view_->SchedulePaint();
-}
-
-bool FindBarHost::IsVisible() {
- return host_->IsVisible();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// FindBarHost, views::FocusChangeListener implementation:
-
-void FindBarHost::FocusWillChange(views::View* focused_before,
- views::View* focused_now) {
- // First we need to determine if one or both of the views passed in are child
- // views of our view.
- bool our_view_before = focused_before && view_->IsParentOf(focused_before);
- bool our_view_now = focused_now && view_->IsParentOf(focused_now);
-
- // When both our_view_before and our_view_now are false, it means focus is
- // changing hands elsewhere in the application (and we shouldn't do anything).
- // Similarly, when both are true, focus is changing hands within the Find
- // window (and again, we should not do anything). We therefore only need to
- // look at when we gain initial focus and when we loose it.
- if (!our_view_before && our_view_now) {
- // We are gaining focus from outside the Find window so we must register
- // a handler for Escape.
- RegisterEscAccelerator();
- } else if (our_view_before && !our_view_now) {
- // We are losing focus to something outside our window so we restore the
- // original handler for Escape.
- UnregisterEscAccelerator();
- }
+ view()->SchedulePaint();
}
////////////////////////////////////////////////////////////////////////////////
@@ -182,53 +107,13 @@ bool FindBarHost::AcceleratorPressed(const views::Accelerator& accelerator) {
}
////////////////////////////////////////////////////////////////////////////////
-// FindBarHost, AnimationDelegate implementation:
-
-void FindBarHost::AnimationProgressed(const Animation* animation) {
- // First, we calculate how many pixels to slide the window.
- gfx::Size pref_size = view_->GetPreferredSize();
- find_dialog_animation_offset_ =
- static_cast<int>((1.0 - animation_->GetCurrentValue()) *
- pref_size.height());
-
- // This call makes sure it appears in the right location, the size and shape
- // is correct and that it slides in the right direction.
- gfx::Rect find_dlg_rect = GetDialogPosition(gfx::Rect());
- SetDialogPosition(find_dlg_rect, false);
-
- // Let the view know if we are animating, and at which offset to draw the
- // edges.
- view_->animation_offset(find_dialog_animation_offset_);
- view_->SchedulePaint();
-}
-
-void FindBarHost::AnimationEnded(const Animation* animation) {
- // Place the find bar in its fully opened state.
- find_dialog_animation_offset_ = 0;
-
- if (!animation_->IsShowing()) {
- // Animation has finished closing.
- host_->Hide();
- } else {
- // Animation has finished opening.
- }
-}
-
-void FindBarHost::GetThemePosition(gfx::Rect* bounds) {
- *bounds = GetDialogPosition(gfx::Rect());
- gfx::Rect toolbar_bounds = browser_view_->GetToolbarBounds();
- gfx::Rect tab_strip_bounds = browser_view_->GetTabStripBounds();
- bounds->Offset(-toolbar_bounds.x(), -tab_strip_bounds.y());
-}
-
-////////////////////////////////////////////////////////////////////////////////
// FindBarTesting implementation:
bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position,
bool* fully_visible) {
if (!find_bar_controller_ ||
#if defined(OS_WIN)
- !::IsWindow(host_->GetNativeView())) {
+ !::IsWindow(host()->GetNativeView())) {
#else
false) {
// TODO(sky): figure out linux side.
@@ -241,21 +126,14 @@ bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position,
}
gfx::Rect window_rect;
- host_->GetBounds(&window_rect, true);
+ host()->GetBounds(&window_rect, true);
if (position)
*position = window_rect.origin();
if (fully_visible)
- *fully_visible = host_->IsVisible() && !IsAnimating();
+ *fully_visible = host()->IsVisible() && !IsAnimating();
return true;
}
-void FindBarHost::GetDialogBounds(gfx::Rect* bounds) {
- DCHECK(bounds);
- // The BrowserView does Layout for the components that we care about
- // positioning relative to, so we ask it to tell us where we should go.
- *bounds = browser_view_->GetFindBarBoundingBox();
-}
-
void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) {
// |w| is used to make it easier to create the part of the polygon that curves
// the right side of the Find window. It essentially keeps track of the
@@ -266,7 +144,7 @@ void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) {
// rightmost background image of the view.
// This polygon array represents the outline of the background image for the
- // dialog. Basically, it encompasses only the visible pixels of the
+ // window. Basically, it encompasses only the visible pixels of the
// concatenated find_dlg_LMR_bg images (where LMR = [left | middle | right]).
static const Path::Point polygon[] = {
{0, 0}, {0, 1}, {2, 3}, {2, 29}, {4, 31},
@@ -287,18 +165,18 @@ void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) {
ScopedRegion region(path.CreateNativeRegion());
// Are we animating?
- if (find_dialog_animation_offset_ > 0) {
+ if (animation_offset() > 0) {
// The animation happens in two steps: First, we clip the window and then in
- // GetDialogPosition we offset the window position so that it still looks
+ // GetWidgetPosition we offset the window position so that it still looks
// attached to the toolbar as it grows. We clip the window by creating a
// rectangle region (that gradually increases as the animation progresses)
// and find the intersection between the two regions using CombineRgn.
// |y| shrinks as the animation progresses from the height of the view down
// to 0 (and reverses when closing).
- int y = find_dialog_animation_offset_;
+ int y = animation_offset();
// |y| shrinking means the animation (visible) region gets larger. In other
- // words: the rectangle grows upward (when the dialog is opening).
+ // words: the rectangle grows upward (when the widget is opening).
Path animation_path;
SkRect animation_rect = { SkIntToScalar(0), SkIntToScalar(y),
SkIntToScalar(max_x), SkIntToScalar(max_y) };
@@ -328,18 +206,18 @@ void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) {
// Now see if we need to truncate the region because parts of it obscures
// the main window border.
- gfx::Rect dialog_bounds;
- GetDialogBounds(&dialog_bounds);
+ gfx::Rect widget_bounds;
+ GetWidgetBounds(&widget_bounds);
// Calculate how much our current position overlaps our boundaries. If we
- // overlap, it means we have too little space to draw the whole dialog and
- // we allow overwriting the scrollbar before we start truncating our dialog.
+ // overlap, it means we have too little space to draw the whole widget and
+ // we allow overwriting the scrollbar before we start truncating our widget.
//
// TODO(brettw) this constant is evil. This is the amount of room we've added
// to the window size, when we set the region, it can change the size.
static const int kAddedWidth = 7;
int difference = (new_pos.right() - kAddedWidth) -
- dialog_bounds.width() -
+ widget_bounds.width() -
views::NativeScrollBar::GetVerticalScrollBarWidth() +
1;
if (difference > 0) {
@@ -363,25 +241,25 @@ void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) {
}
// Window takes ownership of the region.
- host_->SetShape(region.release());
+ host()->SetShape(region.release());
}
gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
// Find the area we have to work with (after accounting for scrollbars, etc).
- gfx::Rect dialog_bounds;
- GetDialogBounds(&dialog_bounds);
- if (dialog_bounds.IsEmpty())
+ gfx::Rect widget_bounds;
+ GetWidgetBounds(&widget_bounds);
+ if (widget_bounds.IsEmpty())
return gfx::Rect();
// Ask the view how large an area it needs to draw on.
- gfx::Size prefsize = view_->GetPreferredSize();
+ gfx::Size prefsize = view()->GetPreferredSize();
- // Place the view in the top right corner of the dialog boundaries (top left
+ // Place the view in the top right corner of the widget boundaries (top left
// for RTL languages).
gfx::Rect view_location;
- int x = view_->UILayoutIsRightToLeft() ?
- dialog_bounds.x() : dialog_bounds.width() - prefsize.width();
- int y = dialog_bounds.y();
+ int x = view()->UILayoutIsRightToLeft() ?
+ widget_bounds.x() : widget_bounds.width() - prefsize.width();
+ int y = widget_bounds.y();
view_location.SetRect(x, y, prefsize.width(), prefsize.height());
// When we get Find results back, we specify a selection rect, which we
@@ -389,18 +267,18 @@ gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
// selection rect (if one was provided).
if (!avoid_overlapping_rect.IsEmpty()) {
// For comparison (with the Intersects function below) we need to account
- // for the fact that we draw the Find dialog relative to the window,
+ // for the fact that we draw the Find widget relative to the Chrome frame,
// whereas the selection rect is relative to the page.
- GetDialogPositionNative(&avoid_overlapping_rect);
+ GetWidgetPositionNative(&avoid_overlapping_rect);
}
gfx::Rect new_pos = FindBarController::GetLocationForFindbarView(
- view_location, dialog_bounds, avoid_overlapping_rect);
+ view_location, widget_bounds, avoid_overlapping_rect);
// While we are animating, the Find window will grow bottoms up so we need to
- // re-position the dialog so that it appears to grow out of the toolbar.
- if (find_dialog_animation_offset_ > 0)
- new_pos.Offset(0, std::min(0, -find_dialog_animation_offset_));
+ // re-position the widget so that it appears to grow out of the toolbar.
+ if (animation_offset() > 0)
+ new_pos.Offset(0, std::min(0, -animation_offset()));
return new_pos;
}
@@ -414,15 +292,15 @@ void FindBarHost::SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) {
// of it it doesn't look like the window crumbles into the toolbar.
UpdateWindowEdges(new_pos);
- SetDialogPositionNative(new_pos, no_redraw);
+ SetWidgetPositionNative(new_pos, no_redraw);
}
void FindBarHost::RestoreSavedFocus() {
- if (focus_tracker_.get() == NULL) {
+ if (focus_tracker() == NULL) {
// TODO(brettw) Focus() should be on TabContentsView.
find_bar_controller_->tab_contents()->Focus();
} else {
- focus_tracker_->FocusLastFocusedExternalView();
+ focus_tracker()->FocusLastFocusedExternalView();
}
}
@@ -432,7 +310,7 @@ FindBarTesting* FindBarHost::GetFindBarTesting() {
void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result,
const string16& find_text) {
- view_->UpdateForResult(result, find_text);
+ find_bar_view()->UpdateForResult(result, find_text);
// We now need to check if the window is obscuring the search results.
if (!result.selection_rect().IsEmpty())
@@ -441,22 +319,9 @@ void FindBarHost::UpdateUIForFindResult(const FindNotificationDetails& result,
// Once we find a match we no longer want to keep track of what had
// focus. EndFindSession will then set the focus to the page content.
if (result.number_of_matches() > 0)
- focus_tracker_.reset(NULL);
-}
-
-void FindBarHost::RegisterEscAccelerator() {
- DCHECK(!esc_accel_target_registered_);
- views::Accelerator escape(base::VKEY_ESCAPE, false, false, false);
- focus_manager_->RegisterAccelerator(escape, this);
- esc_accel_target_registered_ = true;
+ ResetFocusTracker();
}
-void FindBarHost::UnregisterEscAccelerator() {
- DCHECK(esc_accel_target_registered_);
- views::Accelerator escape(base::VKEY_ESCAPE, false, false, false);
- focus_manager_->UnregisterAccelerator(escape, this);
- esc_accel_target_registered_ = false;
-}
bool FindBarHost::MaybeForwardKeystrokeToWebpage(
const views::Textfield::Keystroke& key_stroke) {
@@ -493,3 +358,7 @@ bool FindBarHost::MaybeForwardKeystrokeToWebpage(
render_view_host->ForwardKeyboardEvent(event);
return true;
}
+
+FindBarView* FindBarHost::find_bar_view() {
+ return static_cast<FindBarView*>(view());
+}
diff --git a/chrome/browser/views/find_bar_host.h b/chrome/browser/views/find_bar_host.h
index 4ccc57a..d42ff26 100644
--- a/chrome/browser/views/find_bar_host.h
+++ b/chrome/browser/views/find_bar_host.h
@@ -8,33 +8,23 @@
#include "app/animation.h"
#include "app/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
-#include "base/scoped_ptr.h"
#include "chrome/browser/find_bar.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+#include "chrome/browser/views/dropdown_bar_host.h"
#include "views/controls/textfield/textfield.h"
-#include "views/focus/focus_manager.h"
-#include "views/widget/widget.h"
class BrowserView;
class FindBarController;
class FindBarView;
class FindNotificationDetails;
-class RenderViewHost;
-class SlideAnimation;
-
-namespace views {
-class ExternalFocusTracker;
-class View;
-}
-
////////////////////////////////////////////////////////////////////////////////
//
-// The FindBarHost implements the container window for the
+// The FindBarHost implements the container widget for the
// find-in-page functionality. It uses the appropriate implementation from
// find_bar_host_win.cc or find_bar_host_gtk.cc to draw its content and is
-// responsible for showing, hiding, closing, and moving the window if needed,
-// for example if the window is obscuring the selection results. It also
+// responsible for showing, hiding, closing, and moving the widget if needed,
+// for example if the widget is obscuring the selection results. It also
// receives notifications about the search results and communicates that to
// the view.
//
@@ -43,18 +33,13 @@ class View;
// the BrowserView is attached to the frame's Widget for the first time.
//
////////////////////////////////////////////////////////////////////////////////
-class FindBarHost : public views::AcceleratorTarget,
- public views::FocusChangeListener,
- public AnimationDelegate,
+class FindBarHost : public DropdownBarHost,
public FindBar,
public FindBarTesting {
public:
explicit FindBarHost(BrowserView* browser_view);
virtual ~FindBarHost();
- // Whether we are animating the position of the Find window.
- bool IsAnimating();
-
// Forwards selected keystrokes to the renderer. This is useful to make sure
// that arrow keys and PageUp and PageDown result in scrolling, instead of
// being eaten because the FindBar has focus. Returns true if the keystroke
@@ -62,8 +47,6 @@ class FindBarHost : public views::AcceleratorTarget,
bool MaybeForwardKeystrokeToWebpage(
const views::Textfield::Keystroke& key_stroke);
- bool IsVisible();
-
// FindBar implementation:
virtual FindBarController* GetFindBarController() const {
return find_bar_controller_;
@@ -88,104 +71,36 @@ class FindBarHost : public views::AcceleratorTarget,
virtual void RestoreSavedFocus();
virtual FindBarTesting* GetFindBarTesting();
- // Overridden from views::FocusChangeListener:
- virtual void FocusWillChange(views::View* focused_before,
- views::View* focused_now);
-
- // Overridden from views::AcceleratorTarget:
+ // Overridden from views::AcceleratorTarget in DropdownBarHost class:
virtual bool AcceleratorPressed(const views::Accelerator& accelerator);
- // AnimationDelegate implementation:
- virtual void AnimationProgressed(const Animation* animation);
- virtual void AnimationEnded(const Animation* animation);
-
// FindBarTesting implementation:
virtual bool GetFindBarWindowInfo(gfx::Point* position,
bool* fully_visible);
- // Get the offset with which to paint the theme image.
- void GetThemePosition(gfx::Rect* bounds);
-
- // During testing we can disable animations by setting this flag to true,
- // so that opening and closing the Find box happens instantly, instead of
- // having to poll it while it animates to open/closed status.
- static bool disable_animations_during_testing_;
-
private:
- // Retrieves the boundaries that the find bar has to work with within the
- // Chrome frame window. The resulting rectangle will be a rectangle that
- // overlaps the bottom of the Chrome toolbar by one pixel (so we can create
- // the illusion that the find bar is part of the toolbar) and covers the page
- // area, except that we deflate the rect width by subtracting (from both
- // sides) the width of the toolbar and some extra pixels to account for the
- // width of the Chrome window borders. |bounds| is relative to the browser
- // window. If the function fails to determine the browser window/client area
- // rectangle or the rectangle for the page area then |bounds| will
- // be an empty rectangle.
- void GetDialogBounds(gfx::Rect* bounds);
-
- // The dialog needs rounded edges, so we create a polygon that corresponds to
- // the background images for this window (and make the polygon only contain
- // the pixels that we want to draw). The polygon is then given to SetWindowRgn
- // which changes the window from being a rectangle in shape, to being a rect
- // with curved edges. We also check to see if the region should be truncated
- // to prevent from drawing onto Chrome's window border.
+ // The find bar widget needs rounded edges, so we create a polygon
+ // that corresponds to the background images for this window (and
+ // make the polygon only contain the pixels that we want to
+ // draw). The polygon is then given to SetWindowRgn which changes
+ // the window from being a rectangle in shape, to being a rect with
+ // curved edges. We also check to see if the region should be
+ // truncated to prevent from drawing onto Chrome's window border.
void UpdateWindowEdges(const gfx::Rect& new_pos);
- // Registers this class as the handler for when Escape is pressed. We will
- // unregister once we loose focus. See also: SetFocusChangeListener().
- void RegisterEscAccelerator();
+ // Allows implementation to tweak widget position.
+ void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect);
- // When we loose focus, we unregister the handler for Escape. See
- // also: SetFocusChangeListener().
- void UnregisterEscAccelerator();
-
- // Creates and returns the native Widget.
- views::Widget* CreateHost();
- // Allows implementation to tweak dialog position.
- void SetDialogPositionNative(const gfx::Rect& new_pos, bool no_redraw);
- // Allows implementation to tweak dialog position.
- void GetDialogPositionNative(gfx::Rect* avoid_overlapping_rect);
- // Returns the native view (is a child of the window widget in gtk).
- gfx::NativeView GetNativeView(BrowserView* browser_view);
- // Returns a keyboard event suitable for fowarding.
- NativeWebKeyboardEvent GetKeyboardEvent(
- const TabContents* contents,
- const views::Textfield::Keystroke& key_stroke);
// Allows native implementation to prevent keystrokes from being forwarded.
bool ShouldForwardKeystrokeToWebpageNative(
const views::Textfield::Keystroke& key_stroke);
- // The BrowserView that created us.
- BrowserView* browser_view_;
-
- // Our view, which is responsible for drawing the UI.
- FindBarView* view_;
-
- // The y position pixel offset of the window while animating the Find dialog.
- int find_dialog_animation_offset_;
-
- // The animation class to use when opening the Find window.
- scoped_ptr<SlideAnimation> animation_;
-
- // The focus manager we register with to keep track of focus changes.
- views::FocusManager* focus_manager_;
-
- // True if the accelerator target for Esc key is registered.
- bool esc_accel_target_registered_;
-
- // Tracks and stores the last focused view which is not the FindBarView
- // or any of its children. Used to restore focus once the FindBarView is
- // closed.
- scoped_ptr<views::ExternalFocusTracker> focus_tracker_;
+ // Returns the FindBarView.
+ FindBarView* find_bar_view();
// A pointer back to the owning controller.
FindBarController* find_bar_controller_;
- // Host is the Widget implementation that is created and maintained by the
- // find bar. It contains the FindBarView.
- scoped_ptr<views::Widget> host_;
-
DISALLOW_COPY_AND_ASSIGN(FindBarHost);
};
diff --git a/chrome/browser/views/find_bar_host_browsertest.cc b/chrome/browser/views/find_bar_host_browsertest.cc
index a341d38..d254aa04 100644
--- a/chrome/browser/views/find_bar_host_browsertest.cc
+++ b/chrome/browser/views/find_bar_host_browsertest.cc
@@ -50,6 +50,18 @@ class FindInPageControllerTest : public InProcessBrowserTest {
}
};
+// Platform independent FindInPage that takes |const wchat_t*|
+// as an input.
+int FindInPageWchar(TabContents* tab,
+ const wchar_t* search_str,
+ bool forward,
+ bool case_sensitive,
+ int* ordinal) {
+ return ui_test_utils::FindInPage(
+ tab, WideToUTF16(std::wstring(search_str)),
+ forward, case_sensitive, ordinal);
+}
+
// This test loads a page with frames and starts FindInPage requests.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
HTTPTestServer* server = StartHTTPServer();
@@ -61,72 +73,72 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) {
// Try incremental search (mimicking user typing in).
int ordinal = 0;
TabContents* tab = browser()->GetSelectedTabContents();
- EXPECT_EQ(18, ui_test_utils::FindInPage(tab, L"g",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(18, FindInPageWchar(tab, L"g",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(11, ui_test_utils::FindInPage(tab, L"go",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(11, FindInPageWchar(tab, L"go",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(04, ui_test_utils::FindInPage(tab, L"goo",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(04, FindInPageWchar(tab, L"goo",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(03, ui_test_utils::FindInPage(tab, L"goog",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(03, FindInPageWchar(tab, L"goog",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(02, ui_test_utils::FindInPage(tab, L"googl",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(02, FindInPageWchar(tab, L"googl",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(01, ui_test_utils::FindInPage(tab, L"google",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(01, FindInPageWchar(tab, L"google",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(00, ui_test_utils::FindInPage(tab, L"google!",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(00, FindInPageWchar(tab, L"google!",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
// Negative test (no matches should be found).
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"Non-existing string",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"Non-existing string",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
// 'horse' only exists in the three right frames.
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"horse",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"horse",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// 'cat' only exists in the first frame.
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"cat",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"cat",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Try searching again, should still come up with 1 match.
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"cat",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"cat",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Try searching backwards, ignoring case, should still come up with 1 match.
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"CAT",
- kBack, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"CAT",
+ kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Try case sensitive, should NOT find it.
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"CAT",
- kFwd, kCaseSensitive, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"CAT",
+ kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(0, ordinal);
// Try again case sensitive, but this time with right case.
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"dog",
- kFwd, kCaseSensitive, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"dog",
+ kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(1, ordinal);
// Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame).
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"Hreggvi\u00F0ur",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"Hreggvi\u00F0ur",
- kFwd, kCaseSensitive, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur",
+ kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"hreggvi\u00F0ur",
- kFwd, kCaseSensitive, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"hreggvi\u00F0ur",
+ kFwd, kCaseSensitive, &ordinal));
EXPECT_EQ(0, ordinal);
}
@@ -158,8 +170,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
// Search for a text that exists within a link on the page.
int ordinal = 0;
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab_contents, L"nk",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// End the find session, which should set focus to the link.
@@ -169,8 +181,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) {
EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str());
// Search for a text that exists within a link on the page.
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab_contents, L"Google",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab_contents, L"Google",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Move the selection to link 1, after searching.
@@ -201,29 +213,29 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) {
// '1 in 3' (1st ordinal of a total of 3 matches).
TabContents* tab = browser()->GetSelectedTabContents();
int ordinal = 0;
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"o",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"o",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"o",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
// Go back one match.
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o",
- kBack, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"o",
+ kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"o",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
// This should wrap to the top.
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"o",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// This should go back to the end.
- EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o",
- kBack, kIgnoreCase, &ordinal));
+ EXPECT_EQ(3, FindInPageWchar(tab, L"o",
+ kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
}
@@ -242,8 +254,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Search for a text that exists within a link on the page.
TabContents* tab = browser()->GetSelectedTabContents();
int ordinal = 0;
- EXPECT_EQ(4, ui_test_utils::FindInPage(tab_contents, L"google",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(4, FindInPageWchar(tab_contents,
+ L"google",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Move the selection to link 1, after searching.
@@ -256,8 +269,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Do a find-next after the selection. This should move forward
// from there to the 3rd instance of 'google'.
- EXPECT_EQ(4, ui_test_utils::FindInPage(tab, L"google",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(4, FindInPageWchar(tab,
+ L"google",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
// End the find session.
@@ -278,45 +292,45 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) {
TabContents* tab = browser()->GetSelectedTabContents();
int ordinal = 0;
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(4, ordinal);
// Go back one, which should go back one frame.
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kBack, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(4, ordinal);
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(5, ordinal);
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(6, ordinal);
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(7, ordinal);
// Now we should wrap back to frame 1.
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kFwd, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Now we should wrap back to frame last frame.
EXPECT_EQ(7,
- ui_test_utils::FindInPage(tab, L"a", kBack, kIgnoreCase, &ordinal));
+ FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal));
EXPECT_EQ(7, ordinal);
}
// We could get ordinals out of whack when restarting search in subframes.
-// See http://crbug.com/5132
+// See http://crbug.com/5132.
IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) {
HTTPTestServer* server = StartHTTPServer();
@@ -327,22 +341,22 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) {
// Search for 'goa' three times (6 matches on page).
int ordinal = 0;
TabContents* tab = browser()->GetSelectedTabContents();
- EXPECT_EQ(6, ui_test_utils::FindInPage(tab, L"goa",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(6, FindInPageWchar(tab, L"goa",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(6, ui_test_utils::FindInPage(tab, L"goa",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(6, FindInPageWchar(tab, L"goa",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(2, ordinal);
- EXPECT_EQ(6, ui_test_utils::FindInPage(tab, L"goa",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(6, FindInPageWchar(tab, L"goa",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
// Add space to search (should result in no matches).
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"goa ",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"goa ",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
// Remove the space, should be back to '3 out of 6')
- EXPECT_EQ(6, ui_test_utils::FindInPage(tab, L"goa",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(6, FindInPageWchar(tab, L"goa",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(3, ordinal);
}
@@ -356,11 +370,11 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) {
int ordinal = 0;
TabContents* tab = browser()->GetSelectedTabContents();
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"text",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"text",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(-1, ordinal); // Nothing is selected.
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"Non-existing string",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"Non-existing string",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
}
@@ -383,15 +397,15 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) {
// to find U+0D4C. Still need to investigate further this issue.
int ordinal = 0;
TabContents* tab = browser()->GetSelectedTabContents();
- ui_test_utils::FindInPage(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
- ui_test_utils::FindInPage(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
+ FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
+ FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal);
// This should work fine.
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"\u0D24\u0D46",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"nostring",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"nostring",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
}
@@ -406,8 +420,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) {
// This used to crash the tab.
int ordinal = 0;
- EXPECT_EQ(0, ui_test_utils::FindInPage(browser()->GetSelectedTabContents(),
- L"s", kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(browser()->GetSelectedTabContents(),
+ L"s", kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
}
@@ -429,9 +443,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) {
// This string appears 5 times at the bottom of a long page. If Find restarts
// properly after a timeout, it will find 5 matches, not just 1.
int ordinal = 0;
- EXPECT_EQ(5, ui_test_utils::FindInPage(browser()->GetSelectedTabContents(),
- L"008.xml",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(5, FindInPageWchar(browser()->GetSelectedTabContents(),
+ L"008.xml",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
}
@@ -450,8 +464,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Search for a text that exists within a link on the page.
int ordinal = 0;
- EXPECT_EQ(2, ui_test_utils::FindInPage(tab_contents, L"html ",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
}
@@ -465,7 +479,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) {
ui_test_utils::NavigateToURL(browser(), url);
// Open the Find window with animations disabled.
- FindBarHost::disable_animations_during_testing_ = true;
+ DropdownBarHost::disable_animations_during_testing_ = true;
browser()->ShowFindBar();
gfx::Point position;
@@ -499,7 +513,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
ui_test_utils::NavigateToURL(browser(), url);
// Open the Find window with animations disabled.
- FindBarHost::disable_animations_during_testing_ = true;
+ DropdownBarHost::disable_animations_during_testing_ = true;
browser()->ShowFindBar();
gfx::Point position;
@@ -541,7 +555,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
ui_test_utils::NavigateToURL(browser(), url);
// Open the Find window with animations disabled.
- FindBarHost::disable_animations_during_testing_ = true;
+ DropdownBarHost::disable_animations_during_testing_ = true;
browser()->ShowFindBar();
gfx::Point start_position;
@@ -555,8 +569,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Search for 'dream' which the Find box is obscuring.
int ordinal = 0;
TabContents* tab = browser()->GetSelectedTabContents();
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"dream",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"dream",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Make sure Find box has moved.
@@ -584,8 +598,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
EXPECT_NE(start_position.x(), position.x());
// Search for 'Too much' which the Find box is not obscuring.
- EXPECT_EQ(1, ui_test_utils::FindInPage(tab, L"Too much",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(1, FindInPageWchar(tab, L"Too much",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(1, ordinal);
// Make sure Find box has moved back to its original location.
@@ -606,8 +620,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Search for 'no_match'. No matches should be found.
int ordinal = 0;
TabContents* tab = browser()->GetSelectedTabContents();
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, L"no_match",
- kFwd, kIgnoreCase, &ordinal));
+ EXPECT_EQ(0, FindInPageWchar(tab, L"no_match",
+ kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
// Open another tab (tab B).
@@ -616,7 +630,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Simulate what happens when you press F3 for FindNext. We should get a
// response here (a hang means search was aborted).
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, std::wstring(),
+ EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(),
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
@@ -626,20 +640,43 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
// Simulate what happens when you press F3 for FindNext. We should get a
// response here (a hang means search was aborted).
- EXPECT_EQ(0, ui_test_utils::FindInPage(tab, std::wstring(),
+ EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(),
kFwd, kIgnoreCase, &ordinal));
EXPECT_EQ(0, ordinal);
}
// Make sure Find box grabs the Esc accelerator and restores it again.
-IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
+#if defined(OS_LINUX)
+// TODO(oshima): On Gtk/Linux, a focus out event is asynchronous and
+// hiding a find bar does not immediately update the target
+// accelerator. The last condition fails in most cases due to this
+// behavior. See http://crbug.com/26870.
+IN_PROC_BROWSER_TEST_F(FindInPageControllerTest,
+ DISABLED_AcceleratorRestoring) {
+#else
+ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
+#endif
HTTPTestServer* server = StartHTTPServer();
// First we navigate to any page.
GURL url = server->TestServerPageW(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
+#if defined(OS_WIN)
+ // TODO(oshima): Windows code assumes that NativeView is
+ // assignable from NativeWindow, which is not true on other platforms.
+ // This has to be fixed, probably by having explicit
+ // GetNativeView / GetNativewWindow methods on BrowserWindow.
+ // See http://crbug.com/26873.
gfx::NativeView browser_view = browser()->window()->GetNativeHandle();
+#elif defined(OS_LINUX)
+ gfx::NativeView browser_view =
+ GTK_WIDGET(browser()->window()->GetNativeHandle());
+#else
+ // Mac does not use views.
+ NOTREACHED();
+#endif
+
views::FocusManager* focus_manager =
views::FocusManager::GetFocusManagerForNativeView(browser_view);
@@ -649,7 +686,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
focus_manager->GetCurrentTargetForAccelerator(escape);
EXPECT_TRUE(old_target != NULL);
- // Open the Find box.
+ // Open the Find window with animations disabled.
+ DropdownBarHost::disable_animations_during_testing_ = true;
browser()->ShowFindBar();
// Our Find bar should be the new target.
@@ -663,7 +701,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
browser()->GetFindBarController()->EndFindSession();
// The accelerator for Escape should be back to what it was before.
- EXPECT_EQ(old_target, focus_manager->GetCurrentTargetForAccelerator(escape));
+ EXPECT_EQ(old_target,
+ focus_manager->GetCurrentTargetForAccelerator(escape));
}
// Make sure Find box does not become UI-inactive when no text is in the box as
@@ -676,7 +715,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) {
ui_test_utils::NavigateToURL(browser(), url);
// Open the Find window with animations disabled.
- FindBarHost::disable_animations_during_testing_ = true;
+ DropdownBarHost::disable_animations_during_testing_ = true;
browser()->ShowFindBar();
// Simulate a user clearing the search string. Ideally, we should be
diff --git a/chrome/browser/views/find_bar_host_gtk.cc b/chrome/browser/views/find_bar_host_gtk.cc
index e4a46a2..d9f8986 100644
--- a/chrome/browser/views/find_bar_host_gtk.cc
+++ b/chrome/browser/views/find_bar_host_gtk.cc
@@ -4,56 +4,27 @@
#include "chrome/browser/views/find_bar_host.h"
-#include <gdk/gdkkeysyms.h>
-
#include "chrome/browser/find_bar_controller.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/tab_contents/tab_contents_view_gtk.h"
#include "views/widget/widget_gtk.h"
void FindBarHost::AudibleAlert() {
- // TODO(davemoore) implement
+ // TODO(davemoore) implement.
NOTIMPLEMENTED();
}
-views::Widget* FindBarHost::CreateHost() {
- views::WidgetGtk* host = new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
- // We own the host.
- host->set_delete_on_destroy(false);
- return host;
-}
-
-void FindBarHost::SetDialogPositionNative(const gfx::Rect& new_pos,
- bool no_redraw) {
- host_->SetBounds(new_pos);
- host_->Show();
-}
-
-void FindBarHost::GetDialogPositionNative(gfx::Rect* avoid_overlapping_rect) {
+void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) {
gfx::Rect frame_rect, webcontents_rect;
- host_->GetRootWidget()->GetBounds(&frame_rect, true);
+ host()->GetRootWidget()->GetBounds(&frame_rect, true);
TabContentsView* tab_view = find_bar_controller_->tab_contents()->view();
static_cast<TabContentsViewGtk*>(tab_view)->GetBounds(&webcontents_rect,
true);
avoid_overlapping_rect->Offset(0, webcontents_rect.y() - frame_rect.y());
}
-
-gfx::NativeView FindBarHost::GetNativeView(BrowserView* browser_view) {
- return static_cast<views::WidgetGtk*>(
- browser_view->GetWidget())->window_contents();
-}
-
-
-NativeWebKeyboardEvent FindBarHost::GetKeyboardEvent(
- const TabContents* contents,
- const views::Textfield::Keystroke& key_stroke) {
- return NativeWebKeyboardEvent(key_stroke.event());
-}
-
bool FindBarHost::ShouldForwardKeystrokeToWebpageNative(
- const views::Textfield::Keystroke& key_stroke) {
- return true;
+ const views::Textfield::Keystroke& key_stroke) {
+ return true;
}
diff --git a/chrome/browser/views/find_bar_host_win.cc b/chrome/browser/views/find_bar_host_win.cc
index 7d41f2f..e1e5a50 100644
--- a/chrome/browser/views/find_bar_host_win.cc
+++ b/chrome/browser/views/find_bar_host_win.cc
@@ -12,59 +12,20 @@
#include "views/controls/scrollbar/native_scroll_bar.h"
#include "views/widget/widget_win.h"
-NativeWebKeyboardEvent FindBarHost::GetKeyboardEvent(
- const TabContents* contents,
- const views::Textfield::Keystroke& key_stroke) {
- HWND hwnd = contents->GetContentNativeView();
- return NativeWebKeyboardEvent(
- hwnd, key_stroke.message(), key_stroke.key(), 0);
-}
-
void FindBarHost::AudibleAlert() {
MessageBeep(MB_OK);
}
-views::Widget* FindBarHost::CreateHost() {
- views::WidgetWin* widget = new views::WidgetWin();
- // Don't let WidgetWin manage our lifetime. We want our lifetime to
- // coincide with TabContents.
- widget->set_delete_on_destroy(false);
- widget->set_window_style(WS_CHILD | WS_CLIPCHILDREN);
- widget->set_window_ex_style(WS_EX_TOPMOST);
-
- return widget;
-}
-
-void FindBarHost::SetDialogPositionNative(const gfx::Rect& new_pos,
- bool no_redraw) {
- gfx::Rect window_rect;
- host_->GetBounds(&window_rect, true);
- DWORD swp_flags = SWP_NOOWNERZORDER;
- if (!window_rect.IsEmpty())
- swp_flags |= SWP_NOSIZE;
- if (no_redraw)
- swp_flags |= SWP_NOREDRAW;
- if (!host_->IsVisible())
- swp_flags |= SWP_SHOWWINDOW;
-
- ::SetWindowPos(host_->GetNativeView(), HWND_TOP, new_pos.x(), new_pos.y(),
- new_pos.width(), new_pos.height(), swp_flags);
-}
-
-void FindBarHost::GetDialogPositionNative(gfx::Rect* avoid_overlapping_rect) {
+void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) {
RECT frame_rect = {0}, webcontents_rect = {0};
::GetWindowRect(
- static_cast<views::WidgetWin*>(host_.get())->GetParent(), &frame_rect);
+ static_cast<views::WidgetWin*>(host())->GetParent(), &frame_rect);
::GetWindowRect(
find_bar_controller_->tab_contents()->view()->GetNativeView(),
&webcontents_rect);
avoid_overlapping_rect->Offset(0, webcontents_rect.top - frame_rect.top);
}
-gfx::NativeView FindBarHost::GetNativeView(BrowserView* browser_view) {
- return browser_view->GetWidget()->GetNativeView();
-}
-
bool FindBarHost::ShouldForwardKeystrokeToWebpageNative(
const views::Textfield::Keystroke& key_stroke) {
// We specifically ignore WM_CHAR. See http://crbug.com/10509.
diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc
index b97e7b1..31cab2a 100644
--- a/chrome/browser/views/find_bar_view.cc
+++ b/chrome/browser/views/find_bar_view.cc
@@ -76,15 +76,14 @@ static const int kDefaultCharWidth = 43;
////////////////////////////////////////////////////////////////////////////////
// FindBarView, public:
-FindBarView::FindBarView(FindBarHost* container)
- : container_(container),
+FindBarView::FindBarView(FindBarHost* host)
+ : DropdownBarView(host),
find_text_(NULL),
match_count_text_(NULL),
focus_forwarder_view_(NULL),
find_previous_button_(NULL),
find_next_button_(NULL),
- close_button_(NULL),
- animation_offset_(0) {
+ close_button_(NULL) {
SetID(VIEW_ID_FIND_IN_PAGE);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
@@ -244,7 +243,7 @@ void FindBarView::Paint(gfx::Canvas* canvas) {
// FindInPageWidgetWin::CreateRoundedWindowEdges() for details.
ThemeProvider* tp = GetThemeProvider();
gfx::Rect bounds;
- container_->GetThemePosition(&bounds);
+ host()->GetThemePosition(&bounds);
canvas->TileImageInt(*tp->GetBitmapNamed(IDR_THEME_TOOLBAR),
bounds.x(), bounds.y(), 0, 0, lb.width(), lb.height());
@@ -299,17 +298,17 @@ void FindBarView::Paint(gfx::Canvas* canvas) {
w,
background_height);
- if (animation_offset_ > 0) {
+ if (animation_offset() > 0) {
// While animating we draw the curved edges at the point where the
- // controller told us the top of the window is: |animation_offset_|.
+ // controller told us the top of the window is: |animation_offset()|.
canvas->TileImageInt(*kDialog_left,
lb.x(),
- animation_offset_,
+ animation_offset(),
kDialog_left->width(),
kAnimatingEdgeHeight);
canvas->TileImageInt(*kDialog_right,
lb.right() - kDialog_right->width(),
- animation_offset_,
+ animation_offset(),
kDialog_right->width(),
kAnimatingEdgeHeight);
}
@@ -413,10 +412,10 @@ void FindBarView::ButtonPressed(
case FIND_PREVIOUS_TAG:
case FIND_NEXT_TAG:
if (!find_text_->text().empty()) {
- container_->GetFindBarController()->tab_contents()->StartFinding(
- find_text_->text(),
- sender->tag() == FIND_NEXT_TAG,
- false); // Not case sensitive.
+ find_bar_host()->GetFindBarController()->tab_contents()->
+ StartFinding(find_text_->text(),
+ sender->tag() == FIND_NEXT_TAG,
+ false); // Not case sensitive.
}
if (event.IsMouseEvent()) {
// If mouse event, we move the focus back to the text-field, so that the
@@ -428,7 +427,7 @@ void FindBarView::ButtonPressed(
}
break;
case CLOSE_TAG:
- container_->GetFindBarController()->EndFindSession();
+ find_bar_host()->GetFindBarController()->EndFindSession();
break;
default:
NOTREACHED() << L"Unknown button";
@@ -441,7 +440,7 @@ void FindBarView::ButtonPressed(
void FindBarView::ContentsChanged(views::Textfield* sender,
const string16& new_contents) {
- FindBarController* controller = container_->GetFindBarController();
+ FindBarController* controller = find_bar_host()->GetFindBarController();
DCHECK(controller);
// We must guard against a NULL tab_contents, which can happen if the text
// in the Find box is changed right after the tab is destroyed. Otherwise, it
@@ -465,10 +464,10 @@ void FindBarView::ContentsChanged(views::Textfield* sender,
bool FindBarView::HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& key) {
// If the dialog is not visible, there is no reason to process keyboard input.
- if (!container_->IsVisible())
+ if (!host()->IsVisible())
return false;
- if (container_->MaybeForwardKeystrokeToWebpage(key))
+ if (find_bar_host()->MaybeForwardKeystrokeToWebpage(key))
return true; // Handled, we are done!
if (key.GetKeyboardCode() == base::VKEY_RETURN) {
@@ -476,7 +475,7 @@ bool FindBarView::HandleKeystroke(views::Textfield* sender,
string16 find_string = find_text_->text();
if (!find_string.empty()) {
// Search forwards for enter, backwards for shift-enter.
- container_->GetFindBarController()->tab_contents()->StartFinding(
+ find_bar_host()->GetFindBarController()->tab_contents()->StartFinding(
find_string,
!key.IsShiftHeld(),
false); // Not case sensitive.
@@ -500,3 +499,7 @@ bool FindBarView::FocusForwarderView::OnMousePressed(
}
return true;
}
+
+FindBarHost* FindBarView::find_bar_host() const {
+ return static_cast<FindBarHost*>(host());
+}
diff --git a/chrome/browser/views/find_bar_view.h b/chrome/browser/views/find_bar_view.h
index 184482e..8e74d5f 100644
--- a/chrome/browser/views/find_bar_view.h
+++ b/chrome/browser/views/find_bar_view.h
@@ -8,6 +8,7 @@
#include "base/gfx/size.h"
#include "base/string16.h"
#include "chrome/browser/find_notification_details.h"
+#include "chrome/browser/views/dropdown_bar_view.h"
#include "views/controls/button/button.h"
#include "views/controls/textfield/textfield.h"
@@ -22,12 +23,12 @@ class View;
////////////////////////////////////////////////////////////////////////////////
//
-// The FindInPageView is responsible for drawing the UI controls of the
-// FindInPage window, the find text box, the 'Find' button and the 'Close'
+// The FindBarView is responsible for drawing the UI controls of the
+// FindBar, the find text box, the 'Find' button and the 'Close'
// button. It communicates the user search words to the FindBarHost.
//
////////////////////////////////////////////////////////////////////////////////
-class FindBarView : public views::View,
+class FindBarView : public DropdownBarView,
public views::ButtonListener,
public views::Textfield::Controller {
public:
@@ -38,7 +39,7 @@ class FindBarView : public views::View,
CLOSE_TAG, // The Close button (the 'X').
};
- explicit FindBarView(FindBarHost* container);
+ explicit FindBarView(FindBarHost* host);
virtual ~FindBarView();
// Sets the text displayed in the text box.
@@ -50,17 +51,13 @@ class FindBarView : public views::View,
const string16& find_text);
// Claims focus for the text field and selects its contents.
- void SetFocusAndSelection();
-
- // Updates the view to let it know where the controller is clipping the
- // Find window (while animating the opening or closing of the window).
- void animation_offset(int offset) { animation_offset_ = offset; }
+ virtual void SetFocusAndSelection();
// Overridden from views::View:
virtual void Paint(gfx::Canvas* canvas);
virtual void Layout();
virtual gfx::Size GetPreferredSize();
- virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
+ virtual void ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child);
// Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
@@ -95,9 +92,9 @@ class FindBarView : public views::View,
DISALLOW_COPY_AND_ASSIGN(FocusForwarderView);
};
- // Manages the OS-specific view for the find bar and acts as an intermediary
+ // Returns the OS-specific view for the find bar that acts as an intermediary
// between us and the TabContentsView.
- FindBarHost* container_;
+ FindBarHost* find_bar_host() const;
// The controls in the window.
views::Textfield* find_text_;
@@ -107,12 +104,6 @@ class FindBarView : public views::View,
views::ImageButton* find_next_button_;
views::ImageButton* close_button_;
- // While animating, the controller clips the window and draws only the bottom
- // part of it. The view needs to know the pixel offset at which we are drawing
- // the window so that we can draw the curved edges that attach to the toolbar
- // in the right location.
- int animation_offset_;
-
DISALLOW_COPY_AND_ASSIGN(FindBarView);
};
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 0e800ce..c778347 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -81,6 +81,9 @@
'browser/privacy_blacklist/blacklist_manager_browsertest.cc',
'browser/ssl/ssl_browser_tests.cc',
],
+ 'browser_tests_sources_views_specific': [
+ 'browser/views/find_bar_host_browsertest.cc',
+ ],
'browser_tests_sources_win_specific': [
'browser/extensions/browser_action_apitest.cc',
'browser/extensions/extension_devtools_browsertest.cc',
@@ -92,8 +95,6 @@
'browser/extensions/extension_tabs_apitest.cc',
'browser/extensions/extension_i18n_apitest.cc',
'browser/extensions/extension_popup_apitest.cc',
- 'browser/views/browser_views_accessibility_browsertest.cc',
- 'browser/views/find_bar_host_browsertest.cc',
# TODO(jam): http://crbug.com/15101 These tests fail on Linux and Mac.
'browser/child_process_security_policy_browser_test.cc',
'browser/renderer_host/test/web_cache_manager_browsertest.cc',
@@ -101,6 +102,7 @@
# TODO(jcampan): once the task manager works on Mac, move this test to the
# non win specific section.
'browser/task_manager_browsertest.cc',
+ 'browser/views/browser_views_accessibility_browsertest.cc',
],
'browser_tests_sources_exclude_on_mac': [
'browser/extensions/cross_origin_xhr_apitest.cc',
@@ -2283,6 +2285,11 @@
'browser/views/download_shelf_view.cc',
'browser/views/download_shelf_view.h',
'browser/views/download_started_animation_win.cc',
+ 'browser/views/dropdown_bar_host.cc',
+ 'browser/views/dropdown_bar_host.h',
+ 'browser/views/dropdown_bar_host_gtk.cc',
+ 'browser/views/dropdown_bar_host_win.cc',
+ 'browser/views/dropdown_bar_view.h',
'browser/views/edit_search_engine_dialog.cc',
'browser/views/edit_search_engine_dialog.h',
'browser/views/event_utils.cc',
@@ -2815,6 +2822,10 @@
['include', '^browser/views/download_shelf_view.h'],
['include', '^browser/views/dragged_tab_controller.cc'],
['include', '^browser/views/dragged_tab_controller.h'],
+ ['include', '^browser/views/dropdown_bar_host.cc'],
+ ['include', '^browser/views/dropdown_bar_host.h'],
+ ['include', '^browser/views/dropdown_bar_host_gtk.cc'],
+ ['include', '^browser/views/dropdown_bar_view.h'],
['include', '^browser/views/event_utils.cc'],
['include', '^browser/views/event_utils.h'],
['include', '^browser/views/extensions/extension_install_prompt.cc'],
@@ -6444,6 +6455,11 @@
'../views/views.gyp:views',
],
}],
+ ['OS=="linux" and toolkit_views==1', {
+ 'sources': [
+ '<@(browser_tests_sources_views_specific)',
+ ],
+ }],
['OS=="mac"', {
'sources': [
'app/breakpad_mac_stubs.mm',
@@ -6763,6 +6779,7 @@
# defined in 'variables' at the top of the file.
'<@(browser_tests_sources)',
'<@(browser_tests_sources_win_specific)',
+ '<@(browser_tests_sources_views_specific)',
],
'conditions': [
['OS=="win"', {