| 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 virtual 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 virtual 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 virtual 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 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 virtual 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 virtual const char* GetClassName() const override { |
| 240 return kViewClassName; | 240 return kViewClassName; |
| 241 } | 241 } |
| 242 | 242 |
| 243 private: | 243 private: |
| 244 const GURL& url_; | 244 const GURL& url_; |
| 245 Profile* profile_; | 245 Profile* profile_; |
| 246 | 246 |
| 247 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 247 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 // static | 250 // static |
| 251 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; | 251 const char BookmarkButton::kViewClassName[] = "BookmarkButton"; |
| 252 | 252 |
| 253 // ShortcutButton ------------------------------------------------------------- | 253 // ShortcutButton ------------------------------------------------------------- |
| 254 | 254 |
| 255 // Buttons used for the shortcuts on the bookmark bar. | 255 // Buttons used for the shortcuts on the bookmark bar. |
| 256 | 256 |
| 257 class ShortcutButton : public BookmarkButtonBase { | 257 class ShortcutButton : public BookmarkButtonBase { |
| 258 public: | 258 public: |
| 259 // The internal view class name. | 259 // The internal view class name. |
| 260 static const char kViewClassName[]; | 260 static const char kViewClassName[]; |
| 261 | 261 |
| 262 ShortcutButton(views::ButtonListener* listener, | 262 ShortcutButton(views::ButtonListener* listener, |
| 263 const base::string16& title) | 263 const base::string16& title) |
| 264 : BookmarkButtonBase(listener, title) { | 264 : BookmarkButtonBase(listener, title) { |
| 265 } | 265 } |
| 266 | 266 |
| 267 virtual const char* GetClassName() const OVERRIDE { | 267 virtual const char* GetClassName() const override { |
| 268 return kViewClassName; | 268 return kViewClassName; |
| 269 } | 269 } |
| 270 | 270 |
| 271 private: | 271 private: |
| 272 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); | 272 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 // static | 275 // static |
| 276 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; | 276 const char ShortcutButton::kViewClassName[] = "ShortcutButton"; |
| 277 | 277 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 291 if (!animations_enabled) { | 291 if (!animations_enabled) { |
| 292 // For some reason during testing the events generated by animating | 292 // For some reason during testing the events generated by animating |
| 293 // throw off the test. So, don't animate while testing. | 293 // throw off the test. So, don't animate while testing. |
| 294 show_animation_->Reset(1); | 294 show_animation_->Reset(1); |
| 295 } else { | 295 } else { |
| 296 show_animation_->Show(); | 296 show_animation_->Show(); |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 | 299 |
| 300 virtual bool GetTooltipText(const gfx::Point& p, | 300 virtual bool GetTooltipText(const gfx::Point& p, |
| 301 base::string16* tooltip) const OVERRIDE { | 301 base::string16* tooltip) const override { |
| 302 if (label()->GetPreferredSize().width() > label()->size().width()) | 302 if (label()->GetPreferredSize().width() > label()->size().width()) |
| 303 *tooltip = GetText(); | 303 *tooltip = GetText(); |
| 304 return !tooltip->empty(); | 304 return !tooltip->empty(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | 307 virtual bool IsTriggerableEvent(const ui::Event& e) override { |
| 308 // Left clicks and taps should show the menu contents and right clicks | 308 // 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 | 309 // should show the context menu. They should not trigger the opening of |
| 310 // underlying urls. | 310 // underlying urls. |
| 311 if (e.type() == ui::ET_GESTURE_TAP || | 311 if (e.type() == ui::ET_GESTURE_TAP || |
| 312 (e.IsMouseEvent() && (e.flags() & | 312 (e.IsMouseEvent() && (e.flags() & |
| 313 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) | 313 (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)))) |
| 314 return false; | 314 return false; |
| 315 | 315 |
| 316 if (e.IsMouseEvent()) | 316 if (e.IsMouseEvent()) |
| 317 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; | 317 return ui::DispositionFromEventFlags(e.flags()) != CURRENT_TAB; |
| 318 return false; | 318 return false; |
| 319 } | 319 } |
| 320 | 320 |
| 321 private: | 321 private: |
| 322 scoped_ptr<gfx::SlideAnimation> show_animation_; | 322 scoped_ptr<gfx::SlideAnimation> show_animation_; |
| 323 | 323 |
| 324 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 324 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
| 325 }; | 325 }; |
| 326 | 326 |
| 327 // OverFlowButton (chevron) -------------------------------------------------- | 327 // OverFlowButton (chevron) -------------------------------------------------- |
| 328 | 328 |
| 329 class OverFlowButton : public views::MenuButton { | 329 class OverFlowButton : public views::MenuButton { |
| 330 public: | 330 public: |
| 331 explicit OverFlowButton(BookmarkBarView* owner) | 331 explicit OverFlowButton(BookmarkBarView* owner) |
| 332 : MenuButton(NULL, base::string16(), owner, false), | 332 : MenuButton(NULL, base::string16(), owner, false), |
| 333 owner_(owner) {} | 333 owner_(owner) {} |
| 334 | 334 |
| 335 virtual bool OnMousePressed(const ui::MouseEvent& e) OVERRIDE { | 335 virtual bool OnMousePressed(const ui::MouseEvent& e) override { |
| 336 owner_->StopThrobbing(true); | 336 owner_->StopThrobbing(true); |
| 337 return views::MenuButton::OnMousePressed(e); | 337 return views::MenuButton::OnMousePressed(e); |
| 338 } | 338 } |
| 339 | 339 |
| 340 private: | 340 private: |
| 341 BookmarkBarView* owner_; | 341 BookmarkBarView* owner_; |
| 342 | 342 |
| 343 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); | 343 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); |
| 344 }; | 344 }; |
| 345 | 345 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 DropLocation location; | 413 DropLocation location; |
| 414 }; | 414 }; |
| 415 | 415 |
| 416 // ButtonSeparatorView -------------------------------------------------------- | 416 // ButtonSeparatorView -------------------------------------------------------- |
| 417 | 417 |
| 418 class BookmarkBarView::ButtonSeparatorView : public views::View { | 418 class BookmarkBarView::ButtonSeparatorView : public views::View { |
| 419 public: | 419 public: |
| 420 ButtonSeparatorView() {} | 420 ButtonSeparatorView() {} |
| 421 virtual ~ButtonSeparatorView() {} | 421 virtual ~ButtonSeparatorView() {} |
| 422 | 422 |
| 423 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 423 virtual void OnPaint(gfx::Canvas* canvas) override { |
| 424 DetachableToolbarView::PaintVerticalDivider( | 424 DetachableToolbarView::PaintVerticalDivider( |
| 425 canvas, kSeparatorStartX, height(), 1, | 425 canvas, kSeparatorStartX, height(), 1, |
| 426 DetachableToolbarView::kEdgeDividerColor, | 426 DetachableToolbarView::kEdgeDividerColor, |
| 427 DetachableToolbarView::kMiddleDividerColor, | 427 DetachableToolbarView::kMiddleDividerColor, |
| 428 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR)); | 428 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
| 429 } | 429 } |
| 430 | 430 |
| 431 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 431 virtual gfx::Size GetPreferredSize() const override { |
| 432 // We get the full height of the bookmark bar, so that the height returned | 432 // We get the full height of the bookmark bar, so that the height returned |
| 433 // here doesn't matter. | 433 // here doesn't matter. |
| 434 return gfx::Size(kSeparatorWidth, 1); | 434 return gfx::Size(kSeparatorWidth, 1); |
| 435 } | 435 } |
| 436 | 436 |
| 437 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE { | 437 virtual void GetAccessibleState(ui::AXViewState* state) override { |
| 438 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR); | 438 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR); |
| 439 state->role = ui::AX_ROLE_SPLITTER; | 439 state->role = ui::AX_ROLE_SPLITTER; |
| 440 } | 440 } |
| 441 | 441 |
| 442 private: | 442 private: |
| 443 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); | 443 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); |
| 444 }; | 444 }; |
| 445 | 445 |
| 446 // BookmarkBarView ------------------------------------------------------------ | 446 // BookmarkBarView ------------------------------------------------------------ |
| 447 | 447 |
| (...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1974 DCHECK(apps_page_shortcut_); | 1974 DCHECK(apps_page_shortcut_); |
| 1975 // Only perform layout if required. | 1975 // Only perform layout if required. |
| 1976 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 1976 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
| 1977 browser_->profile(), browser_->host_desktop_type()); | 1977 browser_->profile(), browser_->host_desktop_type()); |
| 1978 if (apps_page_shortcut_->visible() == visible) | 1978 if (apps_page_shortcut_->visible() == visible) |
| 1979 return; | 1979 return; |
| 1980 apps_page_shortcut_->SetVisible(visible); | 1980 apps_page_shortcut_->SetVisible(visible); |
| 1981 UpdateBookmarksSeparatorVisibility(); | 1981 UpdateBookmarksSeparatorVisibility(); |
| 1982 Layout(); | 1982 Layout(); |
| 1983 } | 1983 } |
| OLD | NEW |