Skip to content

Commit

Permalink
views: Pull out DragController class into its own header file.
Browse files Browse the repository at this point in the history
BUG=72040
TEST=None

R=ben@chromium.org

Review URL: http://codereview.chromium.org/7202015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89921 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tfarina@chromium.org committed Jun 21, 2011
1 parent afbf65f commit 3eaa3a8
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 44 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node,

button->ClearMaxTextSize();
button->SetContextMenuController(this);
button->SetDragController(this);
button->set_drag_controller(this);
if (node->is_url()) {
if (model_->GetFavicon(node).width() != 0)
button->SetIcon(model_->GetFavicon(node));
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/bookmarks/bookmark_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ui/base/animation/animation_delegate.h"
#include "views/controls/button/button.h"
#include "views/controls/menu/view_menu_delegate.h"
#include "views/drag_controller.h"

class Browser;
class PageNavigator;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/browser_actions_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ BrowserActionView::BrowserActionView(const Extension* extension,
BrowserActionsContainer* panel)
: panel_(panel) {
button_ = new BrowserActionButton(extension, panel);
button_->SetDragController(panel_);
button_->set_drag_controller(panel_);
AddChildView(button_);
button_->UpdateState();
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/browser_actions_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/view_menu_delegate.h"
#include "views/controls/resize_area.h"
#include "views/drag_controller.h"
#include "views/view.h"

class Browser;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/views/location_bar/location_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ void LocationBarView::Init() {
location_icon_view_ = new LocationIconView(this);
AddChildView(location_icon_view_);
location_icon_view_->SetVisible(true);
location_icon_view_->SetDragController(this);
location_icon_view_->set_drag_controller(this);

ev_bubble_view_ =
new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID,
GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this);
AddChildView(ev_bubble_view_);
ev_bubble_view_->SetVisible(false);
ev_bubble_view_->SetDragController(this);
ev_bubble_view_->set_drag_controller(this);

// URL edit field.
// View container for URL edit field.
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/views/location_bar/location_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ui/gfx/font.h"
#include "ui/gfx/rect.h"
#include "views/controls/native/native_view_host.h"
#include "views/drag_controller.h"

#if defined(OS_WIN)
#include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
Expand Down
2 changes: 1 addition & 1 deletion views/controls/textfield/native_textfield_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent)
DCHECK_NE(parent->style(), Textfield::STYLE_LOWERCASE);

SetContextMenuController(this);
SetDragController(this);
set_drag_controller(this);
}

NativeTextfieldViews::~NativeTextfieldViews() {
Expand Down
1 change: 1 addition & 0 deletions views/controls/textfield/native_textfield_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "views/border.h"
#include "views/controls/textfield/native_textfield_wrapper.h"
#include "views/controls/textfield/textfield_views_model.h"
#include "views/drag_controller.h"
#include "views/ime/text_input_client.h"
#include "views/view.h"

Expand Down
48 changes: 48 additions & 0 deletions views/drag_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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_EVENTS_DRAG_CONTROLLER_H_
#define VIEWS_EVENTS_DRAG_CONTROLLER_H_
#pragma once

namespace gfx {
class Point;
}

namespace ui {
class OSExchangeData;
}

namespace views {
class View;

// DragController is responsible for writing drag data for a view, as well as
// supplying the supported drag operations. Use DragController if you don't
// want to subclass.
class DragController {
public:
// Writes the data for the drag.
virtual void WriteDragDataForView(View* sender,
const gfx::Point& press_pt,
OSExchangeData* data) = 0;

// Returns the supported drag operations (see DragDropTypes for possible
// values). A drag is only started if this returns a non-zero value.
virtual int GetDragOperationsForView(View* sender,
const gfx::Point& p) = 0;

// Returns true if a drag operation can be started.
// |press_pt| represents the coordinates where the mouse was initially
// pressed down. |p| is the current mouse coordinates.
virtual bool CanStartDragForView(View* sender,
const gfx::Point& press_pt,
const gfx::Point& p) = 0;

protected:
virtual ~DragController() {}
};

} // namespace views

#endif // VIEWS_EVENTS_DRAG_CONTROLLER_H_
9 changes: 1 addition & 8 deletions views/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ui/gfx/path.h"
#include "ui/gfx/transform.h"
#include "views/background.h"
#include "views/drag_controller.h"
#include "views/layout/layout_manager.h"
#include "views/views_delegate.h"
#include "views/widget/native_widget_private.h"
Expand Down Expand Up @@ -1010,14 +1011,6 @@ void View::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {

// Drag and drop ---------------------------------------------------------------

void View::SetDragController(DragController* drag_controller) {
drag_controller_ = drag_controller;
}

DragController* View::GetDragController() {
return drag_controller_;
}

bool View::GetDropFormats(
int* formats,
std::set<OSExchangeData::CustomFormat>* custom_formats) {
Expand Down
36 changes: 5 additions & 31 deletions views/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace views {

class Background;
class Border;
class DragController;
class FocusManager;
class FocusTraversable;
class InputMethod;
Expand Down Expand Up @@ -89,33 +90,6 @@ class ContextMenuController {
virtual ~ContextMenuController() {}
};

// DragController is responsible for writing drag data for a view, as well as
// supplying the supported drag operations. Use DragController if you don't
// want to subclass.

class DragController {
public:
// Writes the data for the drag.
virtual void WriteDragDataForView(View* sender,
const gfx::Point& press_pt,
OSExchangeData* data) = 0;

// Returns the supported drag operations (see DragDropTypes for possible
// values). A drag is only started if this returns a non-zero value.
virtual int GetDragOperationsForView(View* sender,
const gfx::Point& p) = 0;

// Returns true if a drag operation can be started.
// |press_pt| represents the coordinates where the mouse was initially
// pressed down. |p| is the current mouse coordinates.
virtual bool CanStartDragForView(View* sender,
const gfx::Point& press_pt,
const gfx::Point& p) = 0;

protected:
virtual ~DragController() {}
};

/////////////////////////////////////////////////////////////////////////////
//
// View class
Expand Down Expand Up @@ -791,10 +765,10 @@ class View : public AcceleratorTarget {

// Drag and drop -------------------------------------------------------------

// Set/get the DragController. See description of DragController for more
// information.
void SetDragController(DragController* drag_controller);
DragController* GetDragController();
DragController* drag_controller() { return drag_controller_; }
void set_drag_controller(DragController* drag_controller) {
drag_controller_ = drag_controller;
}

// During a drag and drop session when the mouse moves the view under the
// mouse is queried for the drop types it supports by way of the
Expand Down
1 change: 1 addition & 0 deletions views/views.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
'controls/tree/tree_view.h',
#'debug_utils.cc',
#'debug_utils.h',
'drag_controller.h',
'drag_utils.cc',
'drag_utils.h',
'drag_utils_gtk.cc',
Expand Down

0 comments on commit 3eaa3a8

Please sign in to comment.