diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 16:09:33 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 16:09:33 +0000 |
commit | 45647af87d1e7e5ed607c6fd82a1ac32a708a725 (patch) | |
tree | 258381d5b333c5749616d97c1fe3a6bc4db50e1d /views | |
parent | ab91de22a8a7eef73958b0b4463de89bd7fdbd12 (diff) | |
download | chromium_src-45647af87d1e7e5ed607c6fd82a1ac32a708a725.zip chromium_src-45647af87d1e7e5ed607c6fd82a1ac32a708a725.tar.gz chromium_src-45647af87d1e7e5ed607c6fd82a1ac32a708a725.tar.bz2 |
views: Move the remaining file from views/ to ui/views/.
BUG=104039
R=ben@chromium.org
TBR=stevenjb@chromium.org
Review URL: http://codereview.chromium.org/8771006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112469 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/accessible_pane_view.cc | 205 | ||||
-rw-r--r-- | views/accessible_pane_view.h | 99 | ||||
-rw-r--r-- | views/accessible_pane_view_unittest.cc | 178 | ||||
-rw-r--r-- | views/background.cc | 118 | ||||
-rw-r--r-- | views/background.h | 103 | ||||
-rw-r--r-- | views/border.cc | 92 | ||||
-rw-r--r-- | views/border.h | 62 | ||||
-rw-r--r-- | views/native_theme_delegate.h | 53 | ||||
-rw-r--r-- | views/native_theme_painter.cc | 56 | ||||
-rw-r--r-- | views/native_theme_painter.h | 45 | ||||
-rw-r--r-- | views/paint_lock.cc | 19 | ||||
-rw-r--r-- | views/paint_lock.h | 36 | ||||
-rw-r--r-- | views/painter.cc | 199 | ||||
-rw-r--r-- | views/painter.h | 88 | ||||
-rw-r--r-- | views/repeat_controller.cc | 45 | ||||
-rw-r--r-- | views/repeat_controller.h | 50 | ||||
-rw-r--r-- | views/run_all_unittests.cc | 34 | ||||
-rw-r--r-- | views/view_constants.cc | 13 | ||||
-rw-r--r-- | views/view_constants.h | 28 | ||||
-rw-r--r-- | views/view_text_utils.cc | 164 | ||||
-rw-r--r-- | views/view_text_utils.h | 76 | ||||
-rw-r--r-- | views/views.gyp | 44 | ||||
-rw-r--r-- | views/views_delegate.h | 91 | ||||
-rw-r--r-- | views/views_export.h | 29 |
24 files changed, 22 insertions, 1905 deletions
diff --git a/views/accessible_pane_view.cc b/views/accessible_pane_view.cc deleted file mode 100644 index e0cce04..0000000 --- a/views/accessible_pane_view.cc +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (c) 2011 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 "views/accessible_pane_view.h" - -#include "base/message_loop.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/views/focus/focus_search.h" -#include "ui/views/focus/view_storage.h" -#include "ui/views/widget/widget.h" - -namespace views { - -AccessiblePaneView::AccessiblePaneView() - : pane_has_focus_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), - focus_manager_(NULL), - home_key_(ui::VKEY_HOME, false, false, false), - end_key_(ui::VKEY_END, false, false, false), - escape_key_(ui::VKEY_ESCAPE, false, false, false), - left_key_(ui::VKEY_LEFT, false, false, false), - right_key_(ui::VKEY_RIGHT, false, false, false) { - focus_search_.reset(new views::FocusSearch(this, true, true)); -} - -AccessiblePaneView::~AccessiblePaneView() { - if (pane_has_focus_) { - focus_manager_->RemoveFocusChangeListener(this); - } -} - -bool AccessiblePaneView::SetPaneFocus(views::View* initial_focus) { - if (!IsVisible()) - return false; - - if (!focus_manager_) - focus_manager_ = GetFocusManager(); - - focus_manager_->StoreFocusedView(); - - // Use the provided initial focus if it's visible and enabled, otherwise - // use the first focusable child. - if (!initial_focus || - !Contains(initial_focus) || - !initial_focus->IsVisible() || - !initial_focus->IsEnabled()) { - initial_focus = GetFirstFocusableChild(); - } - - // Return false if there are no focusable children. - if (!initial_focus) - return false; - - focus_manager_->SetFocusedView(initial_focus); - - // If we already have pane focus, we're done. - if (pane_has_focus_) - return true; - - // Otherwise, set accelerators and start listening for focus change events. - pane_has_focus_ = true; - focus_manager_->RegisterAccelerator(home_key_, this); - focus_manager_->RegisterAccelerator(end_key_, this); - focus_manager_->RegisterAccelerator(escape_key_, this); - focus_manager_->RegisterAccelerator(left_key_, this); - focus_manager_->RegisterAccelerator(right_key_, this); - focus_manager_->AddFocusChangeListener(this); - - return true; -} - -bool AccessiblePaneView::SetPaneFocusAndFocusDefault() { - return SetPaneFocus(GetDefaultFocusableChild()); -} - -views::View* AccessiblePaneView::GetDefaultFocusableChild() { - return NULL; -} - -void AccessiblePaneView::RemovePaneFocus() { - focus_manager_->RemoveFocusChangeListener(this); - pane_has_focus_ = false; - - focus_manager_->UnregisterAccelerator(home_key_, this); - focus_manager_->UnregisterAccelerator(end_key_, this); - focus_manager_->UnregisterAccelerator(escape_key_, this); - focus_manager_->UnregisterAccelerator(left_key_, this); - focus_manager_->UnregisterAccelerator(right_key_, this); -} - -views::View* AccessiblePaneView::GetFirstFocusableChild() { - FocusTraversable* dummy_focus_traversable; - views::View* dummy_focus_traversable_view; - return focus_search_->FindNextFocusableView( - NULL, false, views::FocusSearch::DOWN, false, - &dummy_focus_traversable, &dummy_focus_traversable_view); -} - -views::View* AccessiblePaneView::GetLastFocusableChild() { - FocusTraversable* dummy_focus_traversable; - views::View* dummy_focus_traversable_view; - return focus_search_->FindNextFocusableView( - this, true, views::FocusSearch::DOWN, false, - &dummy_focus_traversable, &dummy_focus_traversable_view); -} - -//////////////////////////////////////////////////////////////////////////////// -// View overrides: - -views::FocusTraversable* AccessiblePaneView::GetPaneFocusTraversable() { - if (pane_has_focus_) - return this; - else - return NULL; -} - -bool AccessiblePaneView::AcceleratorPressed( - const ui::Accelerator& accelerator) { - - const views::View* focused_view = focus_manager_->GetFocusedView(); - if (!Contains(focused_view)) - return false; - - switch (accelerator.key_code()) { - case ui::VKEY_ESCAPE: - RemovePaneFocus(); - focus_manager_->RestoreFocusedView(); - return true; - case ui::VKEY_LEFT: - focus_manager_->AdvanceFocus(true); - return true; - case ui::VKEY_RIGHT: - focus_manager_->AdvanceFocus(false); - return true; - case ui::VKEY_HOME: - focus_manager_->SetFocusedViewWithReason( - GetFirstFocusableChild(), views::FocusManager::kReasonFocusTraversal); - return true; - case ui::VKEY_END: - focus_manager_->SetFocusedViewWithReason( - GetLastFocusableChild(), views::FocusManager::kReasonFocusTraversal); - return true; - default: - return false; - } -} - -void AccessiblePaneView::SetVisible(bool flag) { - if (IsVisible() && !flag && pane_has_focus_) { - RemovePaneFocus(); - focus_manager_->RestoreFocusedView(); - } - View::SetVisible(flag); -} - -void AccessiblePaneView::GetAccessibleState(ui::AccessibleViewState* state) { - state->role = ui::AccessibilityTypes::ROLE_PANE; -} - -//////////////////////////////////////////////////////////////////////////////// -// FocusChangeListener overrides: - -void AccessiblePaneView::OnWillChangeFocus(views::View* focused_before, - views::View* focused_now) { - // Act when focus has changed. -} - -void AccessiblePaneView::OnDidChangeFocus(views::View* focused_before, - views::View* focused_now) { - if (!focused_now) - return; - - views::FocusManager::FocusChangeReason reason = - focus_manager_->focus_change_reason(); - - if (!Contains(focused_now) || - reason == views::FocusManager::kReasonDirectFocusChange) { - // We should remove pane focus (i.e. make most of the controls - // not focusable again) because the focus has left the pane, - // or because the focus changed within the pane due to the user - // directly focusing to a specific view (e.g., clicking on it). - RemovePaneFocus(); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// FocusTraversable overrides: - -views::FocusSearch* AccessiblePaneView::GetFocusSearch() { - DCHECK(pane_has_focus_); - return focus_search_.get(); -} - -views::FocusTraversable* AccessiblePaneView::GetFocusTraversableParent() { - DCHECK(pane_has_focus_); - return NULL; -} - -views::View* AccessiblePaneView::GetFocusTraversableParentView() { - DCHECK(pane_has_focus_); - return NULL; -} - -} // namespace views diff --git a/views/accessible_pane_view.h b/views/accessible_pane_view.h deleted file mode 100644 index 104294e..0000000 --- a/views/accessible_pane_view.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_ACCESSIBLE_PANE_VIEW_H_ -#define VIEWS_ACCESSIBLE_PANE_VIEW_H_ -#pragma once - -#include "base/hash_tables.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "ui/base/accelerators/accelerator.h" -#include "ui/views/focus/focus_manager.h" -#include "ui/views/view.h" - -namespace views { -class FocusSearch; - -// This class provides keyboard access to any view that extends it, typically -// a toolbar. The user sets focus to a control in this view by pressing -// F6 to traverse all panes, or by pressing a shortcut that jumps directly -// to this pane. -class VIEWS_EXPORT AccessiblePaneView : public View, - public FocusChangeListener, - public FocusTraversable { - public: - AccessiblePaneView(); - virtual ~AccessiblePaneView(); - - // Set focus to the pane with complete keyboard access. - // Focus will be restored to the last focused view if the user escapes. - // If |initial_focus| is not NULL, that control will get - // the initial focus, if it's enabled and focusable. Returns true if - // the pane was able to receive focus. - virtual bool SetPaneFocus(View* initial_focus); - - // Set focus to the pane with complete keyboard access, with the - // focus initially set to the default child. Focus will be restored - // to the last focused view if the user escapes. - // Returns true if the pane was able to receive focus. - virtual bool SetPaneFocusAndFocusDefault(); - - // Overridden from View: - virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE; - virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) - OVERRIDE; - virtual void SetVisible(bool flag) OVERRIDE; - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - - // Overridden from FocusChangeListener: - virtual void OnWillChangeFocus(View* focused_before, - View* focused_now) OVERRIDE; - virtual void OnDidChangeFocus(View* focused_before, - View* focused_now) OVERRIDE; - - // Overridden from FocusTraversable: - virtual FocusSearch* GetFocusSearch() OVERRIDE; - virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE; - virtual View* GetFocusTraversableParentView() OVERRIDE; - - protected: - // A subclass can override this to provide a default focusable child - // other than the first focusable child. - virtual View* GetDefaultFocusableChild(); - - // Remove pane focus. - virtual void RemovePaneFocus(); - - void RestoreLastFocusedView(); - - View* GetFirstFocusableChild(); - View* GetLastFocusableChild(); - - bool pane_has_focus_; - - base::WeakPtrFactory<AccessiblePaneView> method_factory_; - - // Save the focus manager rather than calling GetFocusManager(), - // so that we can remove focus listeners in the destructor. - FocusManager* focus_manager_; - - // Our custom focus search implementation that traps focus in this - // pane and traverses all views that are focusable for accessibility, - // not just those that are normally focusable. - scoped_ptr<FocusSearch> focus_search_; - - // Registered accelerators - ui::Accelerator home_key_; - ui::Accelerator end_key_; - ui::Accelerator escape_key_; - ui::Accelerator left_key_; - ui::Accelerator right_key_; - - DISALLOW_COPY_AND_ASSIGN(AccessiblePaneView); -}; - -} // namespace views - -#endif // VIEWS_ACCESSIBLE_PANE_VIEW_H_ diff --git a/views/accessible_pane_view_unittest.cc b/views/accessible_pane_view_unittest.cc deleted file mode 100644 index e554ae7..0000000 --- a/views/accessible_pane_view_unittest.cc +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (c) 2011 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 "views/accessible_pane_view.h" - -#include "ui/base/accelerators/accelerator.h" -#include "ui/views/controls/button/text_button.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/test/views_test_base.h" -#include "ui/views/widget/widget.h" - -namespace views { - -// TODO(alicet): bring pane rotation into views and add tests. -// See browser_view.cc for details. - -typedef ViewsTestBase AccessiblePaneViewTest; - -class TestBarView : public AccessiblePaneView, - public ButtonListener { - public: - TestBarView(); - virtual ~TestBarView(); - - virtual void ButtonPressed(Button* sender, - const views::Event& event) OVERRIDE; - TextButton* child_button() const { return child_button_.get(); } - TextButton* second_child_button() const { return second_child_button_.get(); } - TextButton* third_child_button() const { return third_child_button_.get(); } - TextButton* not_child_button() const { return not_child_button_.get(); } - - const ui::Accelerator& home_key() const { return home_key_; } - const ui::Accelerator& end_key() const { return end_key_; } - const ui::Accelerator& escape_key() const { return escape_key_; } - const ui::Accelerator& left_key() const { return left_key_; } - const ui::Accelerator& right_key() const { return right_key_; } - - virtual View* GetDefaultFocusableChild() OVERRIDE; - - private: - void Init(); - - scoped_ptr<TextButton> child_button_; - scoped_ptr<TextButton> second_child_button_; - scoped_ptr<TextButton> third_child_button_; - scoped_ptr<TextButton> not_child_button_; - - DISALLOW_COPY_AND_ASSIGN(TestBarView); -}; - -TestBarView::TestBarView() { - Init(); -} - -TestBarView::~TestBarView() {} - -void TestBarView::ButtonPressed(views::Button* sender, - const views::Event& event) {} - -void TestBarView::Init() { - SetLayoutManager(new views::FillLayout()); - string16 label; - child_button_.reset(new TextButton(this, label)); - AddChildView(child_button_.get()); - second_child_button_.reset(new TextButton(this, label)); - AddChildView(second_child_button_.get()); - third_child_button_.reset(new TextButton(this, label)); - AddChildView(third_child_button_.get()); - not_child_button_.reset(new TextButton(this, label)); -} - -View* TestBarView::GetDefaultFocusableChild() { - return child_button_.get(); -} - -TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { - TestBarView* test_view = new TestBarView(); - scoped_ptr<Widget> widget(new Widget()); - Widget::InitParams params(Widget::InitParams::TYPE_POPUP); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.bounds = gfx::Rect(50, 50, 650, 650); - widget->Init(params); - View* root = widget->GetRootView(); - root->AddChildView(test_view); - widget->Show(); - - // Set pane focus succeeds, focus on child. - EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); - EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); - EXPECT_EQ(test_view->child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - - // Set focus on non child view, focus failed, stays on pane. - EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); - EXPECT_FALSE(test_view->not_child_button() == - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - EXPECT_EQ(test_view->child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - widget->CloseNow(); - widget.reset(); -} - -TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { - TestBarView* test_view = new TestBarView(); - TestBarView* test_view_2 = new TestBarView(); - scoped_ptr<Widget> widget(new Widget()); - Widget::InitParams params(Widget::InitParams::TYPE_POPUP); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.bounds = gfx::Rect(50, 50, 650, 650); - widget->Init(params); - View* root = widget->GetRootView(); - root->AddChildView(test_view); - root->AddChildView(test_view_2); - widget->Show(); - - // Set pane focus succeeds, focus on child. - EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); - EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); - EXPECT_EQ(test_view->child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - - // Set focus on another test_view, focus move to that pane. - EXPECT_TRUE(test_view_2->SetPaneFocus(test_view_2->second_child_button())); - EXPECT_FALSE(test_view->child_button() == - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - EXPECT_EQ(test_view_2->second_child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - widget->CloseNow(); - widget.reset(); -} - -TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) { - TestBarView* test_view = new TestBarView(); - TestBarView* original_test_view = new TestBarView(); - scoped_ptr<Widget> widget(new Widget()); - Widget::InitParams params(Widget::InitParams::TYPE_POPUP); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.bounds = gfx::Rect(50, 50, 650, 650); - widget->Init(params); - View* root = widget->GetRootView(); - root->AddChildView(original_test_view); - root->AddChildView(test_view); - widget->Show(); - - // Set pane focus on first view. - EXPECT_TRUE(original_test_view->SetPaneFocus( - original_test_view->third_child_button())); - - // Test travesal in second view. - // Set pane focus on second child. - EXPECT_TRUE(test_view->SetPaneFocus(test_view->second_child_button())); - // home - test_view->AcceleratorPressed(test_view->home_key()); - EXPECT_EQ(test_view->child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - // end - test_view->AcceleratorPressed(test_view->end_key()); - EXPECT_EQ(test_view->third_child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - // left - test_view->AcceleratorPressed(test_view->left_key()); - EXPECT_EQ(test_view->second_child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - // right, right - test_view->AcceleratorPressed(test_view->right_key()); - test_view->AcceleratorPressed(test_view->right_key()); - EXPECT_EQ(test_view->child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - - // ESC - test_view->AcceleratorPressed(test_view->escape_key()); - EXPECT_EQ(original_test_view->third_child_button(), - test_view->GetWidget()->GetFocusManager()->GetFocusedView()); - widget->CloseNow(); - widget.reset(); -} -} // namespace views diff --git a/views/background.cc b/views/background.cc deleted file mode 100644 index 717261d..0000000 --- a/views/background.cc +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) 2011 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 "views/background.h" - -#include "base/logging.h" -#include "skia/ext/skia_utils_win.h" -#include "third_party/skia/include/core/SkPaint.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/color_utils.h" -#include "ui/views/view.h" -#include "views/painter.h" - -namespace views { - -// SolidBackground is a trivial Background implementation that fills the -// background in a solid color. -class SolidBackground : public Background { - public: - explicit SolidBackground(const SkColor& color) { - SetNativeControlColor(color); - } - - void Paint(gfx::Canvas* canvas, View* view) const { - // Fill the background. Note that we don't constrain to the bounds as - // canvas is already clipped for us. - canvas->GetSkCanvas()->drawColor(get_color()); - } - - private: - DISALLOW_COPY_AND_ASSIGN(SolidBackground); -}; - -class BackgroundPainter : public Background { - public: - BackgroundPainter(bool owns_painter, Painter* painter) - : owns_painter_(owns_painter), painter_(painter) { - DCHECK(painter); - } - - virtual ~BackgroundPainter() { - if (owns_painter_) - delete painter_; - } - - - void Paint(gfx::Canvas* canvas, View* view) const { - Painter::PaintPainterAt(0, 0, view->width(), view->height(), canvas, - painter_); - } - - private: - bool owns_painter_; - Painter* painter_; - - DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); -}; - -Background::Background() - : color_(SK_ColorWHITE) -#if defined(OS_WIN) - , native_control_brush_(NULL) -#endif -{ -} - -Background::~Background() { -#if defined(OS_WIN) - DeleteObject(native_control_brush_); -#endif -} - -void Background::SetNativeControlColor(SkColor color) { - color_ = color; -#if defined(OS_WIN) - DeleteObject(native_control_brush_); - native_control_brush_ = NULL; -#endif -} - -#if defined(OS_WIN) -HBRUSH Background::GetNativeControlBrush() const { - if (!native_control_brush_) - native_control_brush_ = CreateSolidBrush(skia::SkColorToCOLORREF(color_)); - return native_control_brush_; -} -#endif - -//static -Background* Background::CreateSolidBackground(const SkColor& color) { - return new SolidBackground(color); -} - -//static -Background* Background::CreateStandardPanelBackground() { - return CreateVerticalGradientBackground(SkColorSetRGB(246, 250, 255), - SkColorSetRGB(219, 235, 255)); -} - -//static -Background* Background::CreateVerticalGradientBackground( - const SkColor& color1, const SkColor& color2) { - Background* background = CreateBackgroundPainter( - true, Painter::CreateVerticalGradient(color1, color2)); - background->SetNativeControlColor( - color_utils::AlphaBlend(color1, color2, 128)); - - return background; -} - -//static -Background* Background::CreateBackgroundPainter(bool owns_painter, - Painter* painter) { - return new BackgroundPainter(owns_painter, painter); -} - -} // namespace views diff --git a/views/background.h b/views/background.h deleted file mode 100644 index 7bdd376..0000000 --- a/views/background.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_BACKGROUND_H_ -#define VIEWS_BACKGROUND_H_ -#pragma once - -#include "build/build_config.h" - -#if defined(OS_WIN) -#include <windows.h> -#endif // defined(OS_WIN) - -#include "base/basictypes.h" -#include "third_party/skia/include/core/SkColor.h" -#include "views/views_export.h" - -namespace gfx { -class Canvas; -} - -namespace views { - -class Painter; -class View; - -///////////////////////////////////////////////////////////////////////////// -// -// Background class -// -// A background implements a way for views to paint a background. The -// background can be either solid or based on a gradient. Of course, -// Background can be subclassed to implement various effects. -// -// Any View can have a background. See View::SetBackground() and -// View::OnPaintBackground() -// -///////////////////////////////////////////////////////////////////////////// -class VIEWS_EXPORT Background { - public: - Background(); - virtual ~Background(); - - // Creates a background that fills the canvas in the specified color. - static Background* CreateSolidBackground(const SkColor& color); - - // Creates a background that fills the canvas in the specified color. - static Background* CreateSolidBackground(int r, int g, int b) { - return CreateSolidBackground(SkColorSetRGB(r, g, b)); - } - - // Creates a background that fills the canvas in the specified color. - static Background* CreateSolidBackground(int r, int g, int b, int a) { - return CreateSolidBackground(SkColorSetARGB(a, r, g, b)); - } - - // Creates a background that contains a vertical gradient that varies - // from |color1| to |color2| - static Background* CreateVerticalGradientBackground(const SkColor& color1, - const SkColor& color2); - - // Creates Chrome's standard panel background - static Background* CreateStandardPanelBackground(); - - // Creates a Background from the specified Painter. If owns_painter is - // true, the Painter is deleted when the Border is deleted. - static Background* CreateBackgroundPainter(bool owns_painter, - Painter* painter); - - // Render the background for the provided view - virtual void Paint(gfx::Canvas* canvas, View* view) const = 0; - - // Set a solid, opaque color to be used when drawing backgrounds of native - // controls. Unfortunately alpha=0 is not an option. - void SetNativeControlColor(SkColor color); - - // Returns the "background color". This is equivalent to the color set in - // SetNativeControlColor(). For solid backgrounds, this is the color; for - // gradient backgrounds, it's the midpoint of the gradient; for painter - // backgrounds, this is not useful (returns a default color). - SkColor get_color() const { return color_; } - -#if defined(OS_WIN) - // TODO(port): Make GetNativeControlBrush portable (currently uses HBRUSH). - - // Get the brush that was specified by SetNativeControlColor - HBRUSH GetNativeControlBrush() const; -#endif // defined(OS_WIN) - - private: - SkColor color_; -#if defined(OS_WIN) - // TODO(port): Create portable replacement for HBRUSH. - mutable HBRUSH native_control_brush_; -#endif // defined(OS_WIN) - - DISALLOW_COPY_AND_ASSIGN(Background); -}; - -} // namespace views - -#endif // VIEWS_BACKGROUND_H_ diff --git a/views/border.cc b/views/border.cc deleted file mode 100644 index 3f90159..0000000 --- a/views/border.cc +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2011 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 "views/border.h" - -#include "base/logging.h" -#include "ui/gfx/canvas.h" - -namespace views { - -namespace { - -// A simple border with a fixed thickness and single color. -class SolidBorder : public Border { - public: - SolidBorder(int thickness, SkColor color); - - virtual void Paint(const View& view, gfx::Canvas* canvas) const; - virtual void GetInsets(gfx::Insets* insets) const; - - private: - int thickness_; - SkColor color_; - gfx::Insets insets_; - - DISALLOW_COPY_AND_ASSIGN(SolidBorder); -}; - -SolidBorder::SolidBorder(int thickness, SkColor color) - : thickness_(thickness), - color_(color), - insets_(thickness, thickness, thickness, thickness) { -} - -void SolidBorder::Paint(const View& view, gfx::Canvas* canvas) const { - // Top border. - canvas->FillRect(color_, gfx::Rect(0, 0, view.width(), insets_.top())); - // Left border. - canvas->FillRect(color_, gfx::Rect(0, 0, insets_.left(), view.height())); - // Bottom border. - canvas->FillRect(color_, gfx::Rect(0, view.height() - insets_.bottom(), - view.width(), insets_.bottom())); - // Right border. - canvas->FillRect(color_, gfx::Rect(view.width() - insets_.right(), 0, - insets_.right(), view.height())); -} - -void SolidBorder::GetInsets(gfx::Insets* insets) const { - DCHECK(insets); - insets->Set(insets_.top(), insets_.left(), insets_.bottom(), insets_.right()); -} - -class EmptyBorder : public Border { - public: - EmptyBorder(int top, int left, int bottom, int right) - : top_(top), left_(left), bottom_(bottom), right_(right) {} - - virtual void Paint(const View& view, gfx::Canvas* canvas) const {} - - virtual void GetInsets(gfx::Insets* insets) const { - DCHECK(insets); - insets->Set(top_, left_, bottom_, right_); - } - - private: - int top_; - int left_; - int bottom_; - int right_; - - DISALLOW_COPY_AND_ASSIGN(EmptyBorder); -}; -} - -Border::Border() { -} - -Border::~Border() { -} - -// static -Border* Border::CreateSolidBorder(int thickness, SkColor color) { - return new SolidBorder(thickness, color); -} - -// static -Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) { - return new EmptyBorder(top, left, bottom, right); -} - -} // namespace views diff --git a/views/border.h b/views/border.h deleted file mode 100644 index fc7bdc4..0000000 --- a/views/border.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_BORDER_H_ -#define VIEWS_BORDER_H_ -#pragma once - -#include "third_party/skia/include/core/SkColor.h" -#include "ui/gfx/insets.h" -#include "ui/views/view.h" - -namespace gfx{ -class Canvas; -} - -namespace views { - -class View; - -//////////////////////////////////////////////////////////////////////////////// -// -// Border class. -// -// The border class is used to display a border around a view. -// To set a border on a view, just call SetBorder on the view, for example: -// view->set_border(Border::CreateSolidBorder(1, SkColorSetRGB(25, 25, 112)); -// Once set on a view, the border is owned by the view. -// -// IMPORTANT NOTE: not all views support borders at this point. In order to -// support the border, views should make sure to use bounds excluding the -// border (by calling View::GetLocalBoundsExcludingBorder) when doing layout and -// painting. -// -//////////////////////////////////////////////////////////////////////////////// - -class VIEWS_EXPORT Border { - public: - Border(); - virtual ~Border(); - - // Creates a border that is a simple line of the specified thickness and - // color. - static Border* CreateSolidBorder(int thickness, SkColor color); - - // Creates a border for reserving space. The returned border does not - // paint anything. - static Border* CreateEmptyBorder(int top, int left, int bottom, int right); - - // Renders the border for the specified view. - virtual void Paint(const View& view, gfx::Canvas* canvas) const = 0; - - // Sets the specified insets to the the border insets. - virtual void GetInsets(gfx::Insets* insets) const = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(Border); -}; - -} // namespace views - -#endif // VIEWS_BORDER_H_ diff --git a/views/native_theme_delegate.h b/views/native_theme_delegate.h deleted file mode 100644 index 3ebd4f7..0000000 --- a/views/native_theme_delegate.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_NATIVE_THEME_DELEGATE_H_ -#define VIEWS_NATIVE_THEME_DELEGATE_H_ -#pragma once - -#include "ui/gfx/native_theme.h" -#include "ui/gfx/rect.h" -#include "views/views_export.h" - -namespace views { - -// A delagate that supports animating transtions between different native -// theme states. This delegate can be used to control a native theme Border -// or Painter object. -// -// If animation is onging, the native theme border or painter will -// composite the foreground state over the backgroud state using an alpha -// between 0 and 255 based on the current value of the animation. -class VIEWS_EXPORT NativeThemeDelegate { - public: - virtual ~NativeThemeDelegate() {} - - // Get the native theme part that should be drawn. - virtual gfx::NativeTheme::Part GetThemePart() const = 0; - - // Get the rectangle that should be painted. - virtual gfx::Rect GetThemePaintRect() const = 0; - - // Get the state of the part, along with any extra data needed for drawing. - virtual gfx::NativeTheme::State GetThemeState( - gfx::NativeTheme::ExtraParams* params) const = 0; - - // If the native theme drawign should be animated, return the Animation object - // that controlls it. If no animation is ongoing, NULL may be returned. - virtual const ui::Animation* GetThemeAnimation() const = 0; - - // If animation is onging, this returns the background native theme state. - virtual gfx::NativeTheme::State GetBackgroundThemeState( - gfx::NativeTheme::ExtraParams* params) const = 0; - - // If animation is onging, this returns the foreground native theme state. - // This state will be composited over the background using an alpha value - // based on the current value of the animation. - virtual gfx::NativeTheme::State GetForegroundThemeState( - gfx::NativeTheme::ExtraParams* params) const = 0; -}; - -} // namespace views - -#endif // VIEWS_NATIVE_THEME_DELEGATE_H_ diff --git a/views/native_theme_painter.cc b/views/native_theme_painter.cc deleted file mode 100644 index 584667b9..0000000 --- a/views/native_theme_painter.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2011 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 "views/native_theme_painter.h" - -#include "base/logging.h" -#include "ui/base/animation/animation.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/rect.h" -#include "views/native_theme_delegate.h" - -namespace views { - -NativeThemePainter::NativeThemePainter(NativeThemeDelegate* delegate) - : delegate_(delegate) { - DCHECK(delegate_); -} - -gfx::Size NativeThemePainter::GetPreferredSize() { - const gfx::NativeTheme* theme = gfx::NativeTheme::instance(); - gfx::NativeTheme::ExtraParams extra; - gfx::NativeTheme::State state = delegate_->GetThemeState(&extra); - return theme->GetPartSize(delegate_->GetThemePart(), state, extra); -} - -void NativeThemePainter::Paint(int w, int h, gfx::Canvas* canvas) { - const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); - gfx::NativeTheme::Part part = delegate_->GetThemePart(); - gfx::Rect rect(0, 0, w, h); - - if (delegate_->GetThemeAnimation() != NULL && - delegate_->GetThemeAnimation()->is_animating()) { - // Paint background state. - gfx::NativeTheme::ExtraParams prev_extra; - gfx::NativeTheme::State prev_state = - delegate_->GetBackgroundThemeState(&prev_extra); - native_theme->Paint( - canvas->GetSkCanvas(), part, prev_state, rect, prev_extra); - - // Composite foreground state above it. - gfx::NativeTheme::ExtraParams extra; - gfx::NativeTheme::State state = delegate_->GetForegroundThemeState(&extra); - int alpha = delegate_->GetThemeAnimation()->CurrentValueBetween(0, 255); - canvas->SaveLayerAlpha(static_cast<uint8>(alpha)); - native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra); - canvas->Restore(); - } else { - gfx::NativeTheme::ExtraParams extra; - gfx::NativeTheme::State state = delegate_->GetThemeState(&extra); - native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra); - } -} - -} // namespace views diff --git a/views/native_theme_painter.h b/views/native_theme_painter.h deleted file mode 100644 index 1d52858..0000000 --- a/views/native_theme_painter.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_NATIVE_THEME_PAINTER_H_ -#define VIEWS_NATIVE_THEME_PAINTER_H_ -#pragma once - -#include "base/compiler_specific.h" -#include "views/painter.h" - -namespace gfx { -class Canvas; -class Size; -} - -namespace views { - -class NativeThemeDelegate; - -// A Painter that uses NativeTheme to implement painting and sizing. A -// theme delegate must be given at construction time so that the appropriate -// painting and sizing can be done. -class VIEWS_EXPORT NativeThemePainter : public Painter { - public: - explicit NativeThemePainter(NativeThemeDelegate* delegate); - - virtual ~NativeThemePainter() {} - - // Returns the preferred size of the native part being painted. - gfx::Size GetPreferredSize(); - - private: - // The delegate the controls the appearance of this painter. - NativeThemeDelegate* delegate_; - - // Overridden from Painter: - virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(NativeThemePainter); -}; - -} // namespace views - -#endif // VIEWS_NATIVE_THEME_PAINTER_H_ diff --git a/views/paint_lock.cc b/views/paint_lock.cc deleted file mode 100644 index 3b2ce1d..0000000 --- a/views/paint_lock.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2011 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 "views/paint_lock.h" - -#include "ui/views/view.h" - -namespace views { - -PaintLock::PaintLock(View* view) : view_(view) { - view_->set_painting_enabled(false); -} - -PaintLock::~PaintLock() { - view_->set_painting_enabled(true); -} - -} // namespace views diff --git a/views/paint_lock.h b/views/paint_lock.h deleted file mode 100644 index d194597..0000000 --- a/views/paint_lock.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_PAINT_LOCK_H_ -#define VIEWS_PAINT_LOCK_H_ -#pragma once - -#include "base/basictypes.h" -#include "views/views_export.h" - -namespace views { - -class View; - -// Instances of PaintLock can be created to disable painting of the view -// (compositing is not disabled). When the class is destroyed, painting is -// re-enabled. This can be useful during operations like animations, that are -// sensitive to costly paints, and during which only composting, not painting, -// is required. -class VIEWS_EXPORT PaintLock { - public: - // The paint lock does not own the view. It is an error for the view to be - // destroyed before the lock. - PaintLock(View* view); - ~PaintLock(); - - private: - View* view_; - - DISALLOW_COPY_AND_ASSIGN(PaintLock); -}; - -} // namespace views - -#endif // VIEWS_PAINT_LOCK_H_ diff --git a/views/painter.cc b/views/painter.cc deleted file mode 100644 index 5b2fc12..0000000 --- a/views/painter.cc +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (c) 2011 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 "views/painter.h" - -#include "base/logging.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "third_party/skia/include/effects/SkGradientShader.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/point.h" - -namespace views { - -namespace { - -class GradientPainter : public Painter { - public: - GradientPainter(bool horizontal, const SkColor& top, const SkColor& bottom) - : horizontal_(horizontal) { - colors_[0] = top; - colors_[1] = bottom; - } - - virtual ~GradientPainter() { - } - - void Paint(int w, int h, gfx::Canvas* canvas) { - SkPaint paint; - SkPoint p[2]; - p[0].set(SkIntToScalar(0), SkIntToScalar(0)); - if (horizontal_) - p[1].set(SkIntToScalar(w), SkIntToScalar(0)); - else - p[1].set(SkIntToScalar(0), SkIntToScalar(h)); - - SkShader* s = - SkGradientShader::CreateLinear(p, colors_, NULL, 2, - SkShader::kClamp_TileMode, NULL); - paint.setStyle(SkPaint::kFill_Style); - paint.setShader(s); - // Need to unref shader, otherwise never deleted. - s->unref(); - - canvas->GetSkCanvas()->drawRectCoords( - SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(w), SkIntToScalar(h), - paint); - } - - private: - bool horizontal_; - SkColor colors_[2]; - - DISALLOW_COPY_AND_ASSIGN(GradientPainter); -}; - - -class ImagePainter : public Painter { - public: - ImagePainter(const SkBitmap& image, - const gfx::Insets& insets, - bool paint_center) - : image_(image), - insets_(insets), - paint_center_(paint_center) { - DCHECK(image.width() > insets.width() && - image.height() > insets.height()); - } - - // Paints the images. - virtual void Paint(int w, int h, gfx::Canvas* canvas) { - if (w == image_.width() && h == image_.height()) { - // Early out if the size we're to render at equals the size of the image. - canvas->DrawBitmapInt(image_, 0, 0); - return; - } - // Upper left. - canvas->DrawBitmapInt(image_, 0, 0, insets_.left(), insets_.top(), - 0, 0, insets_.left(), insets_.top(), true); - // Top edge. - canvas->DrawBitmapInt( - image_, - insets_.left(), 0, image_.width() - insets_.width(), insets_.top(), - insets_.left(), 0, w - insets_.width(), insets_.top(), true); - // Upper right. - canvas->DrawBitmapInt( - image_, - image_.width() - insets_.right(), 0, insets_.right(), insets_.top(), - w - insets_.right(), 0, insets_.right(), insets_.top(), true); - // Right edge. - canvas->DrawBitmapInt( - image_, - image_.width() - insets_.right(), insets_.top(), - insets_.right(), image_.height() - insets_.height(), - w - insets_.right(), insets_.top(), insets_.right(), - h - insets_.height(), true); - // Bottom right. - canvas->DrawBitmapInt( - image_, - image_.width() - insets_.right(), image_.height() - insets_.bottom(), - insets_.right(), insets_.bottom(), - w - insets_.right(), h - insets_.bottom(), insets_.right(), - insets_.bottom(), true); - // Bottom edge. - canvas->DrawBitmapInt( - image_, - insets_.left(), image_.height() - insets_.bottom(), - image_.width() - insets_.width(), insets_.bottom(), - insets_.left(), h - insets_.bottom(), w - insets_.width(), - insets_.bottom(), true); - // Bottom left. - canvas->DrawBitmapInt( - image_, - 0, image_.height() - insets_.bottom(), insets_.left(), - insets_.bottom(), - 0, h - insets_.bottom(), insets_.left(), insets_.bottom(), true); - // Left. - canvas->DrawBitmapInt( - image_, - 0, insets_.top(), insets_.left(), image_.height() - insets_.height(), - 0, insets_.top(), insets_.left(), h - insets_.height(), true); - // Center. - if (paint_center_) { - canvas->DrawBitmapInt( - image_, - insets_.left(), insets_.top(), - image_.width() - insets_.width(), image_.height() - insets_.height(), - insets_.left(), insets_.top(), - w - insets_.width(), h - insets_.height(), true); - } - } - - private: - const SkBitmap image_; - const gfx::Insets insets_; - bool paint_center_; - - DISALLOW_COPY_AND_ASSIGN(ImagePainter); -}; - -} // namespace - -// static -void Painter::PaintPainterAt(int x, int y, int w, int h, - gfx::Canvas* canvas, Painter* painter) { - DCHECK(canvas && painter); - if (w < 0 || h < 0) - return; - canvas->Save(); - canvas->Translate(gfx::Point(x, y)); - painter->Paint(w, h, canvas); - canvas->Restore(); -} - -// static -Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { - return new GradientPainter(true, c1, c2); -} - -// static -Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { - return new GradientPainter(false, c1, c2); -} - -// static -Painter* Painter::CreateImagePainter(const SkBitmap& image, - const gfx::Insets& insets, - bool paint_center) { - return new ImagePainter(image, insets, paint_center); -} - -HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - for (int i = 0; i < 3; ++i) - images_[i] = rb.GetBitmapNamed(image_resource_names[i]); - height_ = images_[LEFT]->height(); - DCHECK(images_[LEFT]->height() == images_[RIGHT]->height() && - images_[LEFT]->height() == images_[CENTER]->height()); -} - -void HorizontalPainter::Paint(int w, int h, gfx::Canvas* canvas) { - if (w < (images_[LEFT]->width() + images_[CENTER]->width() + - images_[RIGHT]->width())) { - // No room to paint. - return; - } - canvas->DrawBitmapInt(*images_[LEFT], 0, 0); - canvas->DrawBitmapInt(*images_[RIGHT], w - images_[RIGHT]->width(), 0); - canvas->TileImageInt(*images_[CENTER], - images_[LEFT]->width(), - 0, - w - images_[LEFT]->width() - images_[RIGHT]->width(), - height_); -} - -} // namespace views diff --git a/views/painter.h b/views/painter.h deleted file mode 100644 index 9b8e602..0000000 --- a/views/painter.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_PAINTER_H_ -#define VIEWS_PAINTER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "third_party/skia/include/core/SkColor.h" -#include "views/views_export.h" - -namespace gfx { -class Canvas; -class Insets; -} -class SkBitmap; - -namespace views { - -// Painter, as the name implies, is responsible for painting in a particular -// region. Think of Painter as a Border or Background that can be painted -// in any region of a View. -class VIEWS_EXPORT Painter { - public: - // A convenience method for painting a Painter in a particular region. - // This translates the canvas to x/y and paints the painter. - static void PaintPainterAt(int x, int y, int w, int h, - gfx::Canvas* canvas, Painter* painter); - - // Creates a painter that draws a gradient between the two colors. - static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2); - static Painter* CreateVerticalGradient(SkColor c1, SkColor c2); - - // Creates a painter that divides |image| into nine regions. The four corners - // are rendered at the size specified in insets (for example, the upper - // left corners is rendered at 0x0 with a size of - // insets.left()xinsets.right()). The four edges are stretched to fill the - // destination size. - // Ownership is passed to the caller. - static Painter* CreateImagePainter(const SkBitmap& image, - const gfx::Insets& insets, - bool paint_center); - - virtual ~Painter() {} - - // Paints the painter in the specified region. - virtual void Paint(int w, int h, gfx::Canvas* canvas) = 0; -}; - -// HorizontalPainter paints 3 images into a box: left, center and right. The -// left and right images are drawn to size at the left/right edges of the -// region. The center is tiled in the remaining space. All images must have the -// same height. -class VIEWS_EXPORT HorizontalPainter : public Painter { - public: - // Constructs a new HorizontalPainter loading the specified image names. - // The images must be in the order left, right and center. - explicit HorizontalPainter(const int image_resource_names[]); - - virtual ~HorizontalPainter() {} - - // Paints the images. - virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE; - - // Height of the images. - int height() const { return height_; } - - private: - // The image chunks. - enum BorderElements { - LEFT, - CENTER, - RIGHT - }; - - // The height. - int height_; - // NOTE: the images are owned by ResourceBundle. Don't free them. - SkBitmap* images_[3]; - - DISALLOW_COPY_AND_ASSIGN(HorizontalPainter); -}; - -} // namespace views - -#endif // VIEWS_PAINTER_H_ diff --git a/views/repeat_controller.cc b/views/repeat_controller.cc deleted file mode 100644 index 416b591..0000000 --- a/views/repeat_controller.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2011 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 "views/repeat_controller.h" - -using base::TimeDelta; - -namespace views { - -// The delay before the first and then subsequent repeats. Values taken from -// XUL code: http://mxr.mozilla.org/seamonkey/source/layout/xul/base/src/nsRepeatService.cpp#52 -const int kInitialRepeatDelay = 250; -const int kRepeatDelay = 50; - -/////////////////////////////////////////////////////////////////////////////// -// RepeatController, public: - -RepeatController::RepeatController(const base::Closure& callback) - : callback_(callback) { -} - -RepeatController::~RepeatController() { -} - -void RepeatController::Start() { - // The first timer is slightly longer than subsequent repeats. - timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(kInitialRepeatDelay), - this, &RepeatController::Run); -} - -void RepeatController::Stop() { - timer_.Stop(); -} - -/////////////////////////////////////////////////////////////////////////////// -// RepeatController, private: - -void RepeatController::Run() { - timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(kRepeatDelay), this, - &RepeatController::Run); - callback_.Run(); -} - -} // namespace views diff --git a/views/repeat_controller.h b/views/repeat_controller.h deleted file mode 100644 index 3384cf0..0000000 --- a/views/repeat_controller.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_REPEAT_CONTROLLER_H_ -#define VIEWS_REPEAT_CONTROLLER_H_ -#pragma once - -#include "base/callback.h" -#include "base/timer.h" - -namespace views { - -/////////////////////////////////////////////////////////////////////////////// -// -// RepeatController -// -// An object that handles auto-repeating UI actions. There is a longer initial -// delay after which point repeats become constant. Users provide a callback -// that is notified when each repeat occurs so that they can perform the -// associated action. -// -/////////////////////////////////////////////////////////////////////////////// -class RepeatController { - public: - // The RepeatController takes ownership of this callback object. - explicit RepeatController(const base::Closure& callback); - virtual ~RepeatController(); - - // Start repeating. - void Start(); - - // Stop repeating. - void Stop(); - - private: - // Called when the timer expires. - void Run(); - - // The current timer. - base::OneShotTimer<RepeatController> timer_; - - base::Closure callback_; - - DISALLOW_COPY_AND_ASSIGN(RepeatController); -}; - -} // namespace views - -#endif // #ifndef VIEWS_REPEAT_CONTROLLER_H_ diff --git a/views/run_all_unittests.cc b/views/run_all_unittests.cc deleted file mode 100644 index e675291..0000000 --- a/views/run_all_unittests.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2011 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 "base/test/test_suite.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/base/ui_base_paths.h" -#include "ui/gfx/compositor/test/compositor_test_support.h" -#include "ui/gfx/test/gfx_test_utils.h" -#include "ui/views/view.h" - -class ViewTestSuite : public base::TestSuite { - public: - ViewTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {} - - protected: - virtual void Initialize() { - base::TestSuite::Initialize(); - - ui::RegisterPathProvider(); - ui::ResourceBundle::InitSharedInstance("en-US"); - - ui::CompositorTestSupport::Initialize(); - ui::gfx_test_utils::SetupTestCompositor(); - } - - virtual void Shutdown() { - ui::CompositorTestSupport::Terminate(); - } -}; - -int main(int argc, char** argv) { - return ViewTestSuite(argc, argv).Run(); -} diff --git a/views/view_constants.cc b/views/view_constants.cc deleted file mode 100644 index 0e2ed17..0000000 --- a/views/view_constants.cc +++ /dev/null @@ -1,13 +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 "views/view_constants.h" - -namespace views { - -const int kAutoscrollSize = 10; -const int kAutoscrollRowTimerMS = 200; -const int kDropBetweenPixels = 5; - -} // namespace views diff --git a/views/view_constants.h b/views/view_constants.h deleted file mode 100644 index cdee4bf..0000000 --- a/views/view_constants.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_VIEW_CONSTANTS_H_ -#define VIEWS_VIEW_CONSTANTS_H_ -#pragma once - -#include "views/views_export.h" - -namespace views { - -// Size (width or height) within which the user can hold the mouse and the -// view should scroll. -VIEWS_EXPORT extern const int kAutoscrollSize; - -// Time in milliseconds to autoscroll by a row. This is used during drag and -// drop. -VIEWS_EXPORT extern const int kAutoscrollRowTimerMS; - -// Used to determine whether a drop is on an item or before/after it. If a drop -// occurs kDropBetweenPixels from the top/bottom it is considered before/after -// the item, otherwise it is on the item. -VIEWS_EXPORT extern const int kDropBetweenPixels; - -} // namespace views - -#endif // VIEWS_VIEW_CONSTANTS_H_ diff --git a/views/view_text_utils.cc b/views/view_text_utils.cc deleted file mode 100644 index 739a374..0000000 --- a/views/view_text_utils.cc +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) 2011 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 "views/view_text_utils.h" - -#include "base/i18n/bidi_line_iterator.h" -#include "base/i18n/break_iterator.h" -#include "base/logging.h" -#include "base/utf_string_conversions.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/font.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" -#include "ui/views/controls/label.h" -#include "ui/views/controls/link.h" - -namespace view_text_utils { - -void DrawTextAndPositionUrl(gfx::Canvas* canvas, - views::Label* label, - const string16& text, - views::Link* link, - gfx::Rect* rect, - gfx::Size* position, - bool text_direction_is_rtl, - const gfx::Rect& bounds, - const gfx::Font& font) { - DCHECK(canvas && position); - - // The |text| parameter is potentially a mix of LTR and RTL "runs," where - // a run is a sequence of words that share the same directionality. We - // initialize a bidirectional ICU line iterator and split the text into - // runs that are either strictly LTR or strictly RTL, with no mix. - base::i18n::BiDiLineIterator bidi_line; - if (!bidi_line.Open(text, true, false)) - return; - - // Iterate over each run and draw it. - int run_start = 0; - int run_end = 0; - const int runs = bidi_line.CountRuns(); - for (int run = 0; run < runs; ++run) { - UBiDiLevel level = 0; - bidi_line.GetLogicalRun(run_start, &run_end, &level); - DCHECK(run_end > run_start); - string16 fragment = text.substr(run_start, run_end - run_start); - - // A flag that tells us whether we found LTR text inside RTL text. - bool ltr_inside_rtl_text = - ((level & 1) == UBIDI_LTR) && text_direction_is_rtl; - - // Draw text chunk contained in |fragment|. |position| is relative to the - // top left corner of the label we draw inside, even when drawing RTL. - DrawTextStartingFrom(canvas, label, fragment, position, bounds, font, - text_direction_is_rtl, ltr_inside_rtl_text); - - run_start = run_end; // Advance over what we just drew. - } - - // If the caller is interested in placing a link after this text blurb, we - // figure out here where to place it. - if (link && rect) { - gfx::Size sz = link->GetPreferredSize(); - gfx::Insets insets = link->GetInsets(); - WrapIfWordDoesntFit(sz.width(), font.GetHeight(), position, bounds); - int x = position->width(); - int y = position->height(); - - // Links have a border to allow them to be focused. - y -= insets.top(); - - *rect = gfx::Rect(x, y, sz.width(), sz.height()); - - // Go from relative pixel coordinates (within the label we are drawing - // on) to absolute pixel coordinates (relative to the top left corner of - // the dialog content). - rect->Offset(bounds.x(), bounds.y()); - // And leave some space to draw the link in. - position->Enlarge(sz.width(), 0); - } -} - -void DrawTextStartingFrom(gfx::Canvas* canvas, - views::Label* label, - const string16& text, - gfx::Size* position, - const gfx::Rect& bounds, - const gfx::Font& font, - bool text_direction_is_rtl, - bool ltr_within_rtl) { - // Iterate through line breaking opportunities (which in English would be - // spaces and such). This tells us where to wrap. - string16 text16(text); - base::i18n::BreakIterator iter(text16, - base::i18n::BreakIterator::BREAK_SPACE); - if (!iter.Init()) - return; - - int flags = (text_direction_is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : - gfx::Canvas::TEXT_ALIGN_LEFT); - flags |= gfx::Canvas::MULTI_LINE | gfx::Canvas::HIDE_PREFIX; - - // Iterate over each word in the text, or put in a more locale-neutral way: - // iterate to the next line breaking opportunity. - while (iter.Advance()) { - // Get the word and figure out the dimensions. - string16 word; - if (!ltr_within_rtl) - word = iter.GetString(); // Get the next word. - else - word = text16; // Draw the whole text at once. - - int w = font.GetStringWidth(word), h = font.GetHeight(); - gfx::CanvasSkia::SizeStringInt(word, font, &w, &h, flags); - - // If we exceed the boundaries, we need to wrap. - WrapIfWordDoesntFit(w, font.GetHeight(), position, bounds); - - int x = label->GetMirroredXInView(position->width()) + bounds.x(); - if (text_direction_is_rtl) { - x -= w; - // When drawing LTR strings inside RTL text we need to make sure we - // draw the trailing space (if one exists after the LTR text) to the - // left of the LTR string. - if (ltr_within_rtl && word[word.size() - 1] == ' ') { - int space_w = font.GetStringWidth(ASCIIToUTF16(" ")); - int space_h = font.GetHeight(); - gfx::CanvasSkia::SizeStringInt(ASCIIToUTF16(" "), font, &space_w, - &space_h, flags); - x += space_w; - } - } - int y = position->height() + bounds.y(); - - // Draw the text on the screen (mirrored, if RTL run). - canvas->DrawStringInt(word, font, label->enabled_color(), x, y, w, - font.GetHeight(), flags); - - if (!word.empty() && word[word.size() - 1] == '\x0a') { - // When we come across '\n', we move to the beginning of the next line. - position->set_width(0); - position->Enlarge(0, font.GetHeight()); - } else { - // Otherwise, we advance position to the next word. - position->Enlarge(w, 0); - } - - if (ltr_within_rtl) - break; // LTR within RTL is drawn as one unit, so we are done. - } -} - -void WrapIfWordDoesntFit(int word_width, - int font_height, - gfx::Size* position, - const gfx::Rect& bounds) { - if (position->width() + word_width > bounds.right()) { - position->set_width(0); - position->Enlarge(0, font_height); - } -} - -} // namespace view_text_utils diff --git a/views/view_text_utils.h b/views/view_text_utils.h deleted file mode 100644 index 68ed201..0000000 --- a/views/view_text_utils.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 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. -// -// This file defines utility functions for working with text in views. - -#ifndef VIEWS_VIEW_TEXT_UTILS_H_ -#define VIEWS_VIEW_TEXT_UTILS_H_ -#pragma once - -#include "base/string16.h" -#include "views/views_export.h" - -namespace gfx { -class Canvas; -class Font; -class Rect; -class Size; -} - -namespace views { -class Label; -class Link; -} - -namespace view_text_utils { - -// Draws a string onto the canvas (wrapping if needed) while also keeping -// track of where it ends so we can position a URL after the text. The -// parameter |bounds| represents the boundary we have to work with, |position| -// specifies where to draw the string (relative to the top left corner of the -// |bounds| rectangle and |font| specifies the font to use when drawing. When -// the function returns, the parameter |rect| contains where to draw the URL -// (to the right of where we just drew the text) and |position| is updated to -// reflect where to draw the next string after the URL. |label| is a dummy -// label with the correct width and origin for the text to be written; it's -// used so that the x position can be correctly mirrored in RTL languages. -// |text_direction_is_rtl| is true if an RTL language is being used. -// NOTE: The reason why we need this function is because while Skia knows how -// to wrap text appropriately, it doesn't tell us where it drew the last -// character, which we need to position the URLs within the text. -VIEWS_EXPORT void DrawTextAndPositionUrl(gfx::Canvas* canvas, - views::Label* label, - const string16& text, - views::Link* link, - gfx::Rect* rect, - gfx::Size* position, - bool text_direction_is_rtl, - const gfx::Rect& bounds, - const gfx::Font& font); - -// A helper function for DrawTextAndPositionUrl, which simply draws the text -// from a certain starting point |position| and wraps within bounds. -// |word_for_word| specifies whether to draw the text word for word or whether -// to treat the text as one blurb (similar to the way URL's are treated inside -// RTL text. For details on the other parameters, see DrawTextAndPositionUrl. -void DrawTextStartingFrom(gfx::Canvas* canvas, - views::Label* label, - const string16& text, - gfx::Size* position, - const gfx::Rect& bounds, - const gfx::Font& font, - bool text_direction_is_rtl, - bool word_for_word); - -// A simply utility function that calculates whether a word of width -// |word_width| fits at position |position| within the |bounds| rectangle. If -// not, |position| is updated to wrap to the beginning of the next line. -void WrapIfWordDoesntFit(int word_width, - int font_height, - gfx::Size* position, - const gfx::Rect& bounds); - -} // namespace view_text_utils - -#endif // CHROME_BROWSER_VIEWS_VIEW_TEXT_UTILS_H_ diff --git a/views/views.gyp b/views/views.gyp index 63373b8..3a47930 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -45,30 +45,16 @@ ], 'sources': [ # All .cc, .h under views, except unittests - 'accessible_pane_view.cc', - 'accessible_pane_view.h', - 'background.cc', - 'background.h', - 'border.cc', - 'border.h', - 'native_theme_delegate.h', - 'native_theme_painter.cc', - 'native_theme_painter.h', - 'paint_lock.cc', - 'paint_lock.h', - 'painter.cc', - 'painter.h', - 'repeat_controller.cc', - 'repeat_controller.h', - 'view_constants.cc', - 'view_constants.h', - 'view_text_utils.cc', - 'view_text_utils.h', - 'views_delegate.h', '../ui/views/accessibility/native_view_accessibility_win.cc', '../ui/views/accessibility/native_view_accessibility_win.h', + '../ui/views/accessible_pane_view.cc', + '../ui/views/accessible_pane_view.h', '../ui/views/animation/bounds_animator.cc', '../ui/views/animation/bounds_animator.h', + '../ui/views/background.cc', + '../ui/views/background.h', + '../ui/views/border.cc', + '../ui/views/border.h', '../ui/views/bubble/border_contents_view.cc', '../ui/views/bubble/border_contents_view.h', '../ui/views/bubble/bubble_border.cc', @@ -316,15 +302,29 @@ '../ui/views/metrics_win.cc', '../ui/views/mouse_watcher.cc', '../ui/views/mouse_watcher.h', + '../ui/views/native_theme_delegate.h', + '../ui/views/native_theme_painter.cc', + '../ui/views/native_theme_painter.h', + '../ui/views/paint_lock.cc', + '../ui/views/paint_lock.h', + '../ui/views/painter.cc', + '../ui/views/painter.h', + '../ui/views/repeat_controller.cc', + '../ui/views/repeat_controller.h', '../ui/views/touchui/gesture_manager.cc', '../ui/views/touchui/gesture_manager.h', '../ui/views/touchui/touch_selection_controller.cc', '../ui/views/touchui/touch_selection_controller.h', '../ui/views/view.cc', '../ui/views/view.h', + '../ui/views/view_constants.cc', + '../ui/views/view_constants.h', '../ui/views/view_aura.cc', '../ui/views/view_gtk.cc', + '../ui/views/view_text_utils.cc', + '../ui/views/view_text_utils.h', '../ui/views/view_win.cc', + '../ui/views/views_delegate.h', '../ui/views/widget/aero_tooltip_manager.cc', '../ui/views/widget/aero_tooltip_manager.h', '../ui/views/widget/child_window_message_processor.cc', @@ -507,6 +507,7 @@ '..', ], 'sources': [ + '../ui/views/accessible_pane_view_unittest.cc', '../ui/views/animation/bounds_animator_unittest.cc', '../ui/views/bubble/border_contents_unittest.cc', '../ui/views/bubble/bubble_delegate_unittest.cc', @@ -542,8 +543,7 @@ '../ui/views/widget/native_widget_unittest.cc', '../ui/views/widget/native_widget_win_unittest.cc', '../ui/views/widget/widget_unittest.cc', - 'accessible_pane_view_unittest.cc', - 'run_all_unittests.cc', + '../ui/views/run_all_unittests.cc', '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc', diff --git a/views/views_delegate.h b/views/views_delegate.h deleted file mode 100644 index 210031a..0000000 --- a/views/views_delegate.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_VIEWS_DELEGATE_H_ -#define VIEWS_VIEWS_DELEGATE_H_ -#pragma once - -#include <string> - -#if defined(OS_WIN) -#include <windows.h> -#endif - -#include "base/string16.h" -#include "ui/base/accessibility/accessibility_types.h" -#include "ui/base/ui_base_types.h" -#include "views/views_export.h" - -namespace gfx { -class Rect; -} - -namespace ui { -class Clipboard; -} - -namespace views { - -class View; -class Widget; - -// ViewsDelegate is an interface implemented by an object using the views -// framework. It is used to obtain various high level application utilities -// and perform some actions such as window placement saving. -// -// The embedding app must set views_delegate to assign its ViewsDelegate -// implementation. -class VIEWS_EXPORT ViewsDelegate { - public: - // The active ViewsDelegate used by the views system. - static ViewsDelegate* views_delegate; - - virtual ~ViewsDelegate() {} - - // Gets the clipboard. - virtual ui::Clipboard* GetClipboard() const = 0; - - // Saves the position, size and "show" state for the window with the - // specified name. - virtual void SaveWindowPlacement(const Widget* widget, - const std::string& window_name, - const gfx::Rect& bounds, - ui::WindowShowState show_state) = 0; - - // Retrieves the saved position and size and "show" state for the window with - // the specified name. - virtual bool GetSavedWindowPlacement( - const std::string& window_name, - gfx::Rect* bounds, - ui::WindowShowState* show_state) const = 0; - - virtual void NotifyAccessibilityEvent( - View* view, - ui::AccessibilityTypes::Event event_type) = 0; - - // For accessibility, notify the delegate that a menu item was focused - // so that alternate feedback (speech / magnified text) can be provided. - virtual void NotifyMenuItemFocused(const string16& menu_name, - const string16& menu_item_name, - int item_index, - int item_count, - bool has_submenu) = 0; - -#if defined(OS_WIN) - // Retrieves the default window icon to use for windows if none is specified. - virtual HICON GetDefaultWindowIcon() const = 0; -#endif - - // AddRef/ReleaseRef are invoked while a menu is visible. They are used to - // ensure we don't attempt to exit while a menu is showing. - virtual void AddRef() = 0; - virtual void ReleaseRef() = 0; - - // Converts views::Event::flags to a WindowOpenDisposition. - virtual int GetDispositionForEvent(int event_flags) = 0; -}; - -} // namespace views - -#endif // VIEWS_VIEWS_DELEGATE_H_ diff --git a/views/views_export.h b/views/views_export.h deleted file mode 100644 index 312bf4e..0000000 --- a/views/views_export.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_VIEWS_EXPORT_H_ -#define VIEWS_VIEWS_EXPORT_H_ -#pragma once - -// Defines VIEWS_EXPORT so that functionality implemented by the Views module -// can be exported to consumers. - -#if defined(COMPONENT_BUILD) -#if defined(WIN32) - -#if defined(VIEWS_IMPLEMENTATION) -#define VIEWS_EXPORT __declspec(dllexport) -#else -#define VIEWS_EXPORT __declspec(dllimport) -#endif // defined(VIEWS_IMPLEMENTATION) - -#else // defined(WIN32) -#define VIEWS_EXPORT __attribute__((visibility("default"))) -#endif - -#else // defined(COMPONENT_BUILD) -#define VIEWS_EXPORT -#endif - -#endif // VIEWS_VIEWS_EXPORT_H_ |