blob: ab9b865060f93ca5a671941301561ed8942ed415 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_VIEWS_BOOKMARK_TABLE_VIEW_H_
#define CHROME_BROWSER_VIEWS_BOOKMARK_TABLE_VIEW_H_
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/bookmarks/bookmark_drop_info.h"
#include "chrome/views/controls/menu/menu.h"
#include "chrome/views/controls/table/table_view.h"
class BookmarkModel;
class BookmarkNode;
class BookmarkTableModel;
class ChromeFont;
class OSExchangeData;
class PrefService;
class Profile;
// A TableView implementation that shows a BookmarkTableModel.
// BookmarkTableView provides drag and drop support as well as showing a
// separate set of columns when showing search results.
class BookmarkTableView : public views::TableView {
public:
BookmarkTableView(Profile* profile, BookmarkTableModel* model);
// Drag and drop methods.
virtual bool CanDrop(const OSExchangeData& data);
virtual void OnDragEntered(const views::DropTargetEvent& event);
virtual int OnDragUpdated(const views::DropTargetEvent& event);
virtual void OnDragExited();
virtual int OnPerformDrop(const views::DropTargetEvent& event);
// Sets the parent of the nodes being displayed. For search and recently
// found results |parent| is NULL.
void set_parent_node(BookmarkNode* parent) { parent_node_ = parent; }
// Sets whether the path column should be shown. The path column is shown
// for search results and recently bookmarked.
void SetShowPathColumn(bool show_path_column);
// The model as a BookmarkTableModel.
BookmarkTableModel* bookmark_table_model() const;
// Saves the widths of the table columns.
void SaveColumnConfiguration();
// Sets the text to display on top of the table. This is useful if the table
// is empty and you want to inform the user why.
void SetAltText(const std::wstring& alt_text);
protected:
// Overriden to draw a drop indicator when dropping between rows.
virtual void PostPaint();
// Overriden to start a drag.
virtual LRESULT OnNotify(int w_param, LPNMHDR l_param);
private:
// DropPosition identifies where the drop should occur.
struct DropPosition {
DropPosition() : index(-1), on(false) {}
DropPosition(int index, bool on) : index(index), on(on) {}
bool equals(const DropPosition& position) const {
return index == position.index && on == position.on;
}
// The index into the table model as to where the drop should occur. This
// may == the row count of the table.
int index;
// Whether drop is on the item at the specified index. If false, the drop
// is at the specified index.
bool on;
};
// Information used when we're the drop target of a drag and drop operation.
class DropInfo : public BookmarkDropInfo {
public:
explicit DropInfo(BookmarkTableView* view)
: BookmarkDropInfo(view->GetNativeControlHWND(),
view->content_offset()),
view_(view) {}
// Overriden to invoke UpdateDropInfo.
virtual void Scrolled();
// The position the drop is to occur at.
void set_position(const DropPosition& position) {
position_ = position;
}
const DropPosition& position() { return position_; }
private:
DropPosition position_;
BookmarkTableView* view_;
DISALLOW_COPY_AND_ASSIGN(DropInfo);
};
friend class DropInfo;
// Updates drop info. This is invoked both from OnDragUpdated and when we
// autoscroll during a drop.
int UpdateDropInfo();
// Starts a drop operation.
void BeginDrag();
// Returns the drop operation for the specified position.
int CalculateDropOperation(const DropPosition& position);
// Performs the drop operation.
void OnPerformDropImpl();
// Sets the position of the drop. If this differs from the current position
// UpdateDropIndicator is invoked for old and new values.
void SetDropPosition(const DropPosition& position);
// Invoked from SetDropPosition to update the visual indicator. |turn_on|
// indicates whether the indicator is to be turned on or off.
void UpdateDropIndicator(const DropPosition& position, bool turn_on);
// Determines the drop position for the specified location.
DropPosition CalculateDropPosition(int y);
// Returns the BookmarkNode the drop should occur on.
BookmarkNode* GetDropParentAndIndex(const DropPosition& position,
int* index);
// Returns the bounds of drop indicator shown when the drop is to occur
// between rows (drop_on is false).
RECT GetDropBetweenHighlightRect(int index);
// Resets the columns. BookmarkTableView shows different sets of columns.
// See ShowPathColumn for details.
void UpdateColumns();
// Draws the alt_text_. Does nothing if there is no alt_text_.
void PaintAltText();
// Returns the bounds of the alt text.
gfx::Rect GetAltTextBounds();
// Returns the font used for alt text.
ChromeFont GetAltTextFont();
Profile* profile_;
BookmarkNode* parent_node_;
scoped_ptr<DropInfo> drop_info_;
bool show_path_column_;
std::wstring alt_text_;
DISALLOW_COPY_AND_ASSIGN(BookmarkTableView);
};
#endif // CHROME_BROWSER_VIEWS_BOOKMARK_TABLE_VIEW_H_
|