OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 show_animation_.reset(new gfx::SlideAnimation(this)); | 177 show_animation_.reset(new gfx::SlideAnimation(this)); |
178 if (!animations_enabled) { | 178 if (!animations_enabled) { |
179 // For some reason during testing the events generated by animating | 179 // For some reason during testing the events generated by animating |
180 // throw off the test. So, don't animate while testing. | 180 // throw off the test. So, don't animate while testing. |
181 show_animation_->Reset(1); | 181 show_animation_->Reset(1); |
182 } else { | 182 } else { |
183 show_animation_->Show(); | 183 show_animation_->Show(); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) override { | 187 View* GetTooltipHandlerForPoint(const gfx::Point& point) override { |
188 return HitTestPoint(point) && CanProcessEventsWithinSubtree() ? this : NULL; | 188 return HitTestPoint(point) && CanProcessEventsWithinSubtree() ? this : NULL; |
189 } | 189 } |
190 | 190 |
191 virtual scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const override { | 191 scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const override { |
192 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 192 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
193 border->set_insets(gfx::Insets(kButtonPaddingVertical, | 193 border->set_insets(gfx::Insets(kButtonPaddingVertical, |
194 kButtonPaddingHorizontal, | 194 kButtonPaddingHorizontal, |
195 kButtonPaddingVertical, | 195 kButtonPaddingVertical, |
196 kButtonPaddingHorizontal)); | 196 kButtonPaddingHorizontal)); |
197 return border.Pass(); | 197 return border.Pass(); |
198 } | 198 } |
199 | 199 |
200 virtual bool IsTriggerableEvent(const ui::Event& e) override { | 200 bool IsTriggerableEvent(const ui::Event& e) override { |
201 return e.type() == ui::ET_GESTURE_TAP || | 201 return e.type() == ui::ET_GESTURE_TAP || |
202 e.type() == ui::ET_GESTURE_TAP_DOWN || | 202 e.type() == ui::ET_GESTURE_TAP_DOWN || |
203 event_utils::IsPossibleDispositionEvent(e); | 203 event_utils::IsPossibleDispositionEvent(e); |
204 } | 204 } |
205 | 205 |
206 private: | 206 private: |
207 scoped_ptr<gfx::SlideAnimation> show_animation_; | 207 scoped_ptr<gfx::SlideAnimation> show_animation_; |
208 | 208 |
209 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); | 209 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); |
210 }; | 210 }; |
211 | 211 |
212 // BookmarkButton ------------------------------------------------------------- | 212 // BookmarkButton ------------------------------------------------------------- |
213 | 213 |
214 // Buttons used for the bookmarks on the bookmark bar. | 214 // Buttons used for the bookmarks on the bookmark bar. |
215 | 215 |
216 class BookmarkButton : public BookmarkButtonBase { | 216 class BookmarkButton : public BookmarkButtonBase { |
217 public: | 217 public: |
218 // The internal view class name. | 218 // The internal view class name. |
219 static const char kViewClassName[]; | 219 static const char kViewClassName[]; |
220 | 220 |
221 BookmarkButton(views::ButtonListener* listener, | 221 BookmarkButton(views::ButtonListener* listener, |
222 const GURL& url, | 222 const GURL& url, |
223 const base::string16& title, | 223 const base::string16& title, |
224 Profile* profile) | 224 Profile* profile) |
225 : BookmarkButtonBase(listener, title), | 225 : BookmarkButtonBase(listener, title), |
226 url_(url), | 226 url_(url), |
227 profile_(profile) { | 227 profile_(profile) { |
228 } | 228 } |
229 | 229 |
230 virtual bool GetTooltipText(const gfx::Point& p, | 230 bool GetTooltipText(const gfx::Point& p, |
231 base::string16* tooltip) const override { | 231 base::string16* tooltip) const override { |
232 gfx::Point location(p); | 232 gfx::Point location(p); |
233 ConvertPointToScreen(this, &location); | 233 ConvertPointToScreen(this, &location); |
234 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( | 234 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( |
235 GetWidget(), location, url_, GetText(), profile_); | 235 GetWidget(), location, url_, GetText(), profile_); |
236 return !tooltip->empty(); | 236 return !tooltip->empty(); |
237 } | 237 } |
238 | 238 |
239 virtual const char* GetClassName() const override { | 239 const char* GetClassName() const override { return kViewClassName; } |
240 return kViewClassName; | |
241 } | |
242 | 240 |
243 private: | 241 private: |
244 const GURL& url_; | 242 const GURL& url_; |
245 Profile* profile_; | 243 Profile* profile_; |
246 | 244 |
247 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 245 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
248 }; | 246 }; |
249 | 247 |
250 // static | 248 // static |
251 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; | 249 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; |
252 | 250 |
253 // ShortcutButton ------------------------------------------------------------- | 251 // ShortcutButton ------------------------------------------------------------- |
254 | 252 |
255 // Buttons used for the shortcuts on the bookmark bar. | 253 // Buttons used for the shortcuts on the bookmark bar. |
256 | 254 |
257 class ShortcutButton : public BookmarkButtonBase { | 255 class ShortcutButton : public BookmarkButtonBase { |
258 public: | 256 public: |
259 // The internal view class name. | 257 // The internal view class name. |
260 static const char kViewClassName[]; | 258 static const char kViewClassName[]; |
261 | 259 |
262 ShortcutButton(views::ButtonListener* listener, | 260 ShortcutButton(views::ButtonListener* listener, |
263 const base::string16& title) | 261 const base::string16& title) |
264 : BookmarkButtonBase(listener, title) { | 262 : BookmarkButtonBase(listener, title) { |
265 } | 263 } |
266 | 264 |
267 virtual const char* GetClassName() const override { | 265 const char* GetClassName() const override { return kViewClassName; } |
268 return kViewClassName; | |
269 } | |
270 | 266 |
271 private: | 267 private: |
272 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); | 268 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); |
273 }; | 269 }; |
274 | 270 |
275 // static | 271 // static |
276 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; | 272 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; |
277 | 273 |
278 // BookmarkFolderButton ------------------------------------------------------- | 274 // BookmarkFolderButton ------------------------------------------------------- |
279 | 275 |
(...skipping 10 matching lines...) Expand all Loading... |
290 show_animation_.reset(new gfx::SlideAnimation(this)); | 286 show_animation_.reset(new gfx::SlideAnimation(this)); |
291 if (!animations_enabled) { | 287 if (!animations_enabled) { |
292 // For some reason during testing the events generated by animating | 288 // For some reason during testing the events generated by animating |
293 // throw off the test. So, don't animate while testing. | 289 // throw off the test. So, don't animate while testing. |
294 show_animation_->Reset(1); | 290 show_animation_->Reset(1); |
295 } else { | 291 } else { |
296 show_animation_->Show(); | 292 show_animation_->Show(); |
297 } | 293 } |
298 } | 294 } |
299 | 295 |
300 virtual bool GetTooltipText(const gfx::Point& p, | 296 bool GetTooltipText(const gfx::Point& p, |
301 base::string16* tooltip) const override { | 297 base::string16* tooltip) const override { |
302 if (label()->GetPreferredSize().width() > label()->size().width()) | 298 if (label()->GetPreferredSize().width() > label()->size().width()) |
303 *tooltip = GetText(); | 299 *tooltip = GetText(); |
304 return !tooltip->empty(); | 300 return !tooltip->empty(); |
305 } | 301 } |
306 | 302 |
307 virtual bool IsTriggerableEvent(const ui::Event& e) override { | 303 bool IsTriggerableEvent(const ui::Event& e) override { |
308 // Left clicks and taps should show the menu contents and right clicks | 304 // Left clicks and taps should show the menu contents and right clicks |
309 // should show the context menu. They should not trigger the opening of | 305 // should show the context menu. They should not trigger the opening of |
310 // underlying urls. | 306 // underlying urls. |
311 if (e.type() == ui::ET_GESTURE_TAP || | 307 if (e.type() == ui::ET_GESTURE_TAP || |
312 (e.IsMouseEvent() && (e.flags() & | 308 (e.IsMouseEvent() && (e.flags() & |
313 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) | 309 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) |
314 return false; | 310 return false; |
315 | 311 |
316 if (e.IsMouseEvent()) | 312 if (e.IsMouseEvent()) |
317 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; | 313 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; |
318 return false; | 314 return false; |
319 } | 315 } |
320 | 316 |
321 private: | 317 private: |
322 scoped_ptr<gfx::SlideAnimation> show_animation_; | 318 scoped_ptr<gfx::SlideAnimation> show_animation_; |
323 | 319 |
324 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 320 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
325 }; | 321 }; |
326 | 322 |
327 // OverFlowButton (chevron) -------------------------------------------------- | 323 // OverFlowButton (chevron) -------------------------------------------------- |
328 | 324 |
329 class OverFlowButton : public views::MenuButton { | 325 class OverFlowButton : public views::MenuButton { |
330 public: | 326 public: |
331 explicit OverFlowButton(BookmarkBarView* owner) | 327 explicit OverFlowButton(BookmarkBarView* owner) |
332 : MenuButton(NULL, base::string16(), owner, false), | 328 : MenuButton(NULL, base::string16(), owner, false), |
333 owner_(owner) {} | 329 owner_(owner) {} |
334 | 330 |
335 virtual bool OnMousePressed(const ui::MouseEvent& e) override { | 331 bool OnMousePressed(const ui::MouseEvent& e) override { |
336 owner_->StopThrobbing(true); | 332 owner_->StopThrobbing(true); |
337 return views::MenuButton::OnMousePressed(e); | 333 return views::MenuButton::OnMousePressed(e); |
338 } | 334 } |
339 | 335 |
340 private: | 336 private: |
341 BookmarkBarView* owner_; | 337 BookmarkBarView* owner_; |
342 | 338 |
343 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); | 339 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); |
344 }; | 340 }; |
345 | 341 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 BookmarkNodeData data; | 407 BookmarkNodeData data; |
412 | 408 |
413 DropLocation location; | 409 DropLocation location; |
414 }; | 410 }; |
415 | 411 |
416 // ButtonSeparatorView -------------------------------------------------------- | 412 // ButtonSeparatorView -------------------------------------------------------- |
417 | 413 |
418 class BookmarkBarView::ButtonSeparatorView : public views::View { | 414 class BookmarkBarView::ButtonSeparatorView : public views::View { |
419 public: | 415 public: |
420 ButtonSeparatorView() {} | 416 ButtonSeparatorView() {} |
421 virtual ~ButtonSeparatorView() {} | 417 ~ButtonSeparatorView() override {} |
422 | 418 |
423 virtual void OnPaint(gfx::Canvas* canvas) override { | 419 void OnPaint(gfx::Canvas* canvas) override { |
424 DetachableToolbarView::PaintVerticalDivider( | 420 DetachableToolbarView::PaintVerticalDivider( |
425 canvas, kSeparatorStartX, height(), 1, | 421 canvas, kSeparatorStartX, height(), 1, |
426 DetachableToolbarView::kEdgeDividerColor, | 422 DetachableToolbarView::kEdgeDividerColor, |
427 DetachableToolbarView::kMiddleDividerColor, | 423 DetachableToolbarView::kMiddleDividerColor, |
428 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR)); | 424 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
429 } | 425 } |
430 | 426 |
431 virtual gfx::Size GetPreferredSize() const override { | 427 gfx::Size GetPreferredSize() const override { |
432 // We get the full height of the bookmark bar, so that the height returned | 428 // We get the full height of the bookmark bar, so that the height returned |
433 // here doesn't matter. | 429 // here doesn't matter. |
434 return gfx::Size(kSeparatorWidth, 1); | 430 return gfx::Size(kSeparatorWidth, 1); |
435 } | 431 } |
436 | 432 |
437 virtual void GetAccessibleState(ui::AXViewState* state) override { | 433 void GetAccessibleState(ui::AXViewState* state) override { |
438 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR); | 434 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR); |
439 state->role = ui::AX_ROLE_SPLITTER; | 435 state->role = ui::AX_ROLE_SPLITTER; |
440 } | 436 } |
441 | 437 |
442 private: | 438 private: |
443 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); | 439 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); |
444 }; | 440 }; |
445 | 441 |
446 // BookmarkBarView ------------------------------------------------------------ | 442 // BookmarkBarView ------------------------------------------------------------ |
447 | 443 |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1955 return; | 1951 return; |
1956 apps_page_shortcut_->SetVisible(visible); | 1952 apps_page_shortcut_->SetVisible(visible); |
1957 UpdateBookmarksSeparatorVisibility(); | 1953 UpdateBookmarksSeparatorVisibility(); |
1958 LayoutAndPaint(); | 1954 LayoutAndPaint(); |
1959 } | 1955 } |
1960 | 1956 |
1961 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 1957 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
1962 if (UpdateOtherAndManagedButtonsVisibility()) | 1958 if (UpdateOtherAndManagedButtonsVisibility()) |
1963 LayoutAndPaint(); | 1959 LayoutAndPaint(); |
1964 } | 1960 } |
OLD | NEW |