diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 22:34:59 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 22:34:59 +0000 |
commit | ca32a43d3d00983134f0ecec4e43a5a8dc0b61da (patch) | |
tree | 247221d443cf96540b8db75ae3c631ec163e256a /views/controls | |
parent | 06cafed03fc3a63eb1282d1416c3629faa33c762 (diff) | |
download | chromium_src-ca32a43d3d00983134f0ecec4e43a5a8dc0b61da.zip chromium_src-ca32a43d3d00983134f0ecec4e43a5a8dc0b61da.tar.gz chromium_src-ca32a43d3d00983134f0ecec4e43a5a8dc0b61da.tar.bz2 |
Makes views not draw focus for native controls on Gtk. As Gtk renders
the focus for us, this resulted in double the focus indicators.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/468004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33739 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/button/native_button.cc | 6 | ||||
-rw-r--r-- | views/controls/button/native_button.h | 1 | ||||
-rw-r--r-- | views/controls/combobox/combobox.cc | 6 | ||||
-rw-r--r-- | views/controls/combobox/combobox.h | 1 | ||||
-rw-r--r-- | views/controls/native/native_view_host.cc | 9 | ||||
-rw-r--r-- | views/controls/native/native_view_host.h | 9 | ||||
-rw-r--r-- | views/controls/slider/slider.cc | 6 | ||||
-rw-r--r-- | views/controls/slider/slider.h | 1 | ||||
-rw-r--r-- | views/controls/tabbed_pane/tabbed_pane.cc | 6 | ||||
-rw-r--r-- | views/controls/tabbed_pane/tabbed_pane.h | 1 | ||||
-rw-r--r-- | views/controls/table/table_view2.cc | 6 | ||||
-rw-r--r-- | views/controls/table/table_view2.h | 2 | ||||
-rw-r--r-- | views/controls/textfield/textfield.cc | 20 | ||||
-rw-r--r-- | views/controls/textfield/textfield.h | 1 |
14 files changed, 63 insertions, 12 deletions
diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc index 811fb56..a8f22dd 100644 --- a/views/controls/button/native_button.cc +++ b/views/controls/button/native_button.cc @@ -12,6 +12,7 @@ #include "app/l10n_util.h" #include "base/keyboard_codes.h" #include "base/logging.h" +#include "views/controls/native/native_view_host.h" namespace views { @@ -191,6 +192,11 @@ void NativeButton::Focus() { // keyboard messages). } +void NativeButton::PaintFocusBorder(gfx::Canvas* canvas) { + if (NativeViewHost::kRenderNativeControlFocus) + View::PaintFocusBorder(canvas); +} + //////////////////////////////////////////////////////////////////////////////// // NativeButton, protected: diff --git a/views/controls/button/native_button.h b/views/controls/button/native_button.h index c1ecfb8..f69b2b6 100644 --- a/views/controls/button/native_button.h +++ b/views/controls/button/native_button.h @@ -54,6 +54,7 @@ class NativeButton : public Button { virtual void Layout(); virtual void SetEnabled(bool flag); virtual void Focus(); + virtual void PaintFocusBorder(gfx::Canvas* canvas); protected: virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); diff --git a/views/controls/combobox/combobox.cc b/views/controls/combobox/combobox.cc index e184dcb..1f5c461 100644 --- a/views/controls/combobox/combobox.cc +++ b/views/controls/combobox/combobox.cc @@ -8,6 +8,7 @@ #include "base/keyboard_codes.h" #include "base/logging.h" #include "views/controls/combobox/native_combobox_wrapper.h" +#include "views/controls/native/native_view_host.h" namespace views { @@ -79,6 +80,11 @@ bool Combobox::SkipDefaultKeyEventProcessing(const KeyEvent& e) { return native_wrapper_ && native_wrapper_->IsDropdownOpen(); } +void Combobox::PaintFocusBorder(gfx::Canvas* canvas) { + if (NativeViewHost::kRenderNativeControlFocus) + View::PaintFocusBorder(canvas); +} + void Combobox::Focus() { // Forward the focus to the wrapper. if (native_wrapper_) diff --git a/views/controls/combobox/combobox.h b/views/controls/combobox/combobox.h index 105aa54..1380051 100644 --- a/views/controls/combobox/combobox.h +++ b/views/controls/combobox/combobox.h @@ -54,6 +54,7 @@ class Combobox : public View { virtual void Layout(); virtual void SetEnabled(bool enabled); virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e); + virtual void PaintFocusBorder(gfx::Canvas* canvas); protected: virtual void Focus(); diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc index 5f22a00..ce2e4d02 100644 --- a/views/controls/native/native_view_host.cc +++ b/views/controls/native/native_view_host.cc @@ -14,6 +14,15 @@ namespace views { // static const char NativeViewHost::kViewClassName[] = "views/NativeViewHost"; +#if defined(OS_LINUX) +// GTK renders the focus. +// static +const bool NativeViewHost::kRenderNativeControlFocus = false; +#else +// static +const bool NativeViewHost::kRenderNativeControlFocus = true; +#endif + //////////////////////////////////////////////////////////////////////////////// // NativeViewHost, public: diff --git a/views/controls/native/native_view_host.h b/views/controls/native/native_view_host.h index 116fbe0..9970901 100644 --- a/views/controls/native/native_view_host.h +++ b/views/controls/native/native_view_host.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ -#define VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ +#ifndef VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ +#define VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ #include <string> @@ -23,6 +23,9 @@ class NativeViewHost : public View { // The NativeViewHost's class name. static const char kViewClassName[]; + // Should views render the focus when on native controls? + static const bool kRenderNativeControlFocus; + NativeViewHost(); virtual ~NativeViewHost(); @@ -100,4 +103,4 @@ class NativeViewHost : public View { } // namespace views -#endif // VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ +#endif // VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ diff --git a/views/controls/slider/slider.cc b/views/controls/slider/slider.cc index ede29246..581bc9a 100644 --- a/views/controls/slider/slider.cc +++ b/views/controls/slider/slider.cc @@ -7,6 +7,7 @@ #include <string> #include "views/controls/slider/native_slider_wrapper.h" +#include "views/controls/native/native_view_host.h" #include "views/widget/widget.h" namespace views { @@ -88,6 +89,11 @@ void Slider::Focus() { } } +void Slider::PaintFocusBorder(gfx::Canvas* canvas) { + if (NativeViewHost::kRenderNativeControlFocus) + View::PaintFocusBorder(canvas); +} + void Slider::ViewHierarchyChanged(bool is_add, View* parent, View* child) { if (is_add && !native_wrapper_ && GetWidget()) { // The native wrapper's lifetime will be managed by the view hierarchy after diff --git a/views/controls/slider/slider.h b/views/controls/slider/slider.h index 2e44d8a..00079c4 100644 --- a/views/controls/slider/slider.h +++ b/views/controls/slider/slider.h @@ -71,6 +71,7 @@ class Slider : public View { virtual gfx::Size GetPreferredSize(); virtual bool IsFocusable() const; virtual void SetEnabled(bool enabled); + virtual void PaintFocusBorder(gfx::Canvas* canvas); protected: virtual void Focus(); diff --git a/views/controls/tabbed_pane/tabbed_pane.cc b/views/controls/tabbed_pane/tabbed_pane.cc index d7db00d..6e649ee 100644 --- a/views/controls/tabbed_pane/tabbed_pane.cc +++ b/views/controls/tabbed_pane/tabbed_pane.cc @@ -6,6 +6,7 @@ #include "base/keyboard_codes.h" #include "base/logging.h" +#include "views/controls/native/native_view_host.h" #include "views/controls/tabbed_pane/native_tabbed_pane_wrapper.h" namespace views { @@ -115,4 +116,9 @@ void TabbedPane::Focus() { // messages). } +void TabbedPane::PaintFocusBorder(gfx::Canvas* canvas) { + if (NativeViewHost::kRenderNativeControlFocus) + View::PaintFocusBorder(canvas); +} + } // namespace views diff --git a/views/controls/tabbed_pane/tabbed_pane.h b/views/controls/tabbed_pane/tabbed_pane.h index e713ff8..e5793be 100644 --- a/views/controls/tabbed_pane/tabbed_pane.h +++ b/views/controls/tabbed_pane/tabbed_pane.h @@ -70,6 +70,7 @@ class TabbedPane : public View { virtual std::string GetClassName() const; virtual void Layout(); virtual void Focus(); + virtual void PaintFocusBorder(gfx::Canvas* canvas); protected: // The object that actually implements the tabbed-pane. diff --git a/views/controls/table/table_view2.cc b/views/controls/table/table_view2.cc index 36ba072..e9bb42b 100644 --- a/views/controls/table/table_view2.cc +++ b/views/controls/table/table_view2.cc @@ -6,6 +6,7 @@ #include "views/controls/table/table_view2.h" #include "app/table_model.h" +#include "views/controls/native/native_view_host.h" #include "views/controls/table/table_view_observer.h" namespace views { @@ -303,6 +304,11 @@ void TableView2::Layout() { } } +void TableView2::PaintFocusBorder(gfx::Canvas* canvas) { + if (NativeViewHost::kRenderNativeControlFocus) + View::PaintFocusBorder(canvas); +} + size_t TableView2::GetVisibleColumnCount() { return visible_columns_.size(); } diff --git a/views/controls/table/table_view2.h b/views/controls/table/table_view2.h index 3c8e821..7d83953 100644 --- a/views/controls/table/table_view2.h +++ b/views/controls/table/table_view2.h @@ -172,6 +172,8 @@ class TableView2 : public View, public TableModelObserver { const gfx::Rect& current); virtual void Layout(); + virtual void PaintFocusBorder(gfx::Canvas* canvas); + // Used by tests. virtual gfx::NativeView GetTestingHandle(); diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index e906337..e12138e 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -9,20 +9,17 @@ #endif #include "app/gfx/insets.h" -#if defined(OS_WIN) -#include "app/win_util.h" -#include "base/win_util.h" -#endif - -#if defined(OS_LINUX) -#include "base/keyboard_code_conversion_gtk.h" -#endif #include "base/keyboard_codes.h" #include "base/string_util.h" +#include "views/controls/native/native_view_host.h" #include "views/controls/textfield/native_textfield_wrapper.h" #include "views/widget/widget.h" -#if defined(OS_WIN) +#if defined(OS_LINUX) +#include "base/keyboard_code_conversion_gtk.h" +#elif defined(OS_WIN) +#include "app/win_util.h" +#include "base/win_util.h" // TODO(beng): this should be removed when the OS_WIN hack from // ViewHierarchyChanged is removed. #include "views/controls/textfield/native_textfield_win.h" @@ -225,6 +222,11 @@ bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) { return false; } +void Textfield::PaintFocusBorder(gfx::Canvas* canvas) { + if (NativeViewHost::kRenderNativeControlFocus) + View::PaintFocusBorder(canvas); +} + void Textfield::SetEnabled(bool enabled) { View::SetEnabled(enabled); if (native_wrapper_) diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h index 79266d0..3810d82 100644 --- a/views/controls/textfield/textfield.h +++ b/views/controls/textfield/textfield.h @@ -200,6 +200,7 @@ class Textfield : public View { virtual void AboutToRequestFocusFromTabTraversal(bool reverse); virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e); virtual void SetEnabled(bool enabled); + virtual void PaintFocusBorder(gfx::Canvas* canvas); protected: virtual void Focus(); |