Chromium Code Reviews| Index: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| index c83f681f30f53d859fd91c54802319aaf7ea7688..3fc12a52a2a0cf3bfee1a6ed37f0c6adb7a04708 100644 |
| --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| @@ -13,7 +13,6 @@ |
| #include "base/bind.h" |
| #include "base/i18n/rtl.h" |
| -#include "base/location.h" |
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/metrics/histogram_macros.h" |
| @@ -25,7 +24,6 @@ |
| #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| #include "chrome/browser/browser_process.h" |
| -#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/defaults.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/search/search.h" |
| @@ -64,13 +62,7 @@ |
| #include "components/omnibox/browser/omnibox_view.h" |
| #include "components/prefs/pref_service.h" |
| #include "components/url_formatter/elide_url.h" |
| -#include "content/public/browser/notification_details.h" |
| -#include "content/public/browser/notification_source.h" |
| -#include "content/public/browser/page_navigator.h" |
| -#include "content/public/browser/render_view_host.h" |
| -#include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/user_metrics.h" |
| -#include "content/public/browser/web_contents.h" |
| #include "extensions/browser/extension_registry.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/extension_set.h" |
| @@ -78,7 +70,6 @@ |
| #include "ui/base/dragdrop/drag_utils.h" |
| #include "ui/base/dragdrop/os_exchange_data.h" |
| #include "ui/base/l10n/l10n_util.h" |
| -#include "ui/base/material_design/material_design_controller.h" |
| #include "ui/base/page_transition_types.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/theme_provider.h" |
| @@ -129,12 +120,6 @@ static const int kNewTabHorizontalPadding = 2; |
| // Maximum size of buttons on the bookmark bar. |
| static const int kMaxButtonWidth = 150; |
| -// The color gradient start value close to the edge of the divider. |
| -static const SkColor kEdgeDividerColor = SkColorSetRGB(222, 234, 248); |
| - |
| -// The color gradient value for the middle of the divider. |
| -static const SkColor kMiddleDividerColor = SkColorSetRGB(194, 205, 212); |
| - |
| // Number of pixels the attached bookmark bar overlaps with the toolbar. |
| static const int kToolbarAttachedBookmarkBarOverlap = 3; |
| @@ -142,15 +127,11 @@ static const int kToolbarAttachedBookmarkBarOverlap = 3; |
| static const int kDetachedTopMargin = 1; // When attached, we use 0 and let the |
| // toolbar above serve as the margin. |
| static const int kBottomMargin = 2; |
| -// The margin at the start and end of the bar, in dp, indexed by MD mode. |
| -static const int kHorizontalMargin[] = {1, 4, 4}; |
| +static const int kHorizontalMargin = 4; |
| // Padding between buttons. |
| static const int kButtonPadding = 0; |
| -// Color of the drop indicator. |
| -static const SkColor kDropIndicatorColor = SK_ColorBLACK; |
| - |
| // Width of the drop indicator. |
| static const int kDropIndicatorWidth = 2; |
| @@ -158,11 +139,8 @@ static const int kDropIndicatorWidth = 2; |
| static const int kSeparatorMargin = 1; |
| // Width of the separator between the recently bookmarked button and the |
| -// overflow indicator, indexed by MD mode. |
| -static const int kSeparatorWidth[] = {4, 9, 9}; |
| - |
| -// Starting x-coordinate of the separator line within a separator. |
| -static const int kSeparatorStartX = 2; |
| +// overflow indicator. |
| +static const int kSeparatorWidth = 9; |
| // Left-padding for the instructional text. |
| static const int kInstructionsPadding = 6; |
| @@ -186,10 +164,6 @@ gfx::ImageSkia* GetImageSkiaNamed(int id) { |
| return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); |
| } |
| -int GetHorizontalMargin() { |
| - return kHorizontalMargin[ui::MaterialDesignController::GetMode()]; |
| -} |
| - |
| gfx::Rect CalculateInkDropBounds(const gfx::Size& size) { |
| gfx::Rect ink_drop_bounds(size); |
| ink_drop_bounds.Inset(0, 1); |
| @@ -206,11 +180,9 @@ class BookmarkButtonBase : public views::LabelButton { |
| const base::string16& title) |
| : LabelButton(listener, title) { |
| SetElideBehavior(kElideBehavior); |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - SetInkDropMode(InkDropMode::ON); |
| - set_has_ink_drop_action_on_click(true); |
| - SetFocusPainter(nullptr); |
| - } |
| + SetInkDropMode(InkDropMode::ON); |
| + set_has_ink_drop_action_on_click(true); |
| + SetFocusPainter(nullptr); |
| show_animation_.reset(new gfx::SlideAnimation(this)); |
| if (!animations_enabled) { |
| // For some reason during testing the events generated by animating |
| @@ -222,7 +194,8 @@ class BookmarkButtonBase : public views::LabelButton { |
| } |
| View* GetTooltipHandlerForPoint(const gfx::Point& point) override { |
| - return HitTestPoint(point) && CanProcessEventsWithinSubtree() ? this : NULL; |
| + return HitTestPoint(point) && CanProcessEventsWithinSubtree() ? this |
| + : nullptr; |
| } |
| std::unique_ptr<LabelButtonBorder> CreateDefaultBorder() const override { |
| @@ -336,10 +309,8 @@ class BookmarkMenuButtonBase : public views::MenuButton { |
| views::MenuButtonListener* menu_button_listener, |
| bool show_menu_marker) |
| : MenuButton(title, menu_button_listener, show_menu_marker) { |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - SetInkDropMode(InkDropMode::ON); |
| - SetFocusPainter(nullptr); |
| - } |
| + SetInkDropMode(InkDropMode::ON); |
| + SetFocusPainter(nullptr); |
| } |
| std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override { |
| @@ -511,79 +482,36 @@ struct BookmarkBarView::DropInfo { |
| // ButtonSeparatorView -------------------------------------------------------- |
| -// Paints a themed gradient divider at location |x|. |height| is the full |
| -// height of the view you want to paint the divider into, not the height of |
| -// the divider. The height of the divider will become: |
| -// |height| - 2 * |vertical_padding|. |
| -// The color of the divider is a gradient starting with |top_color| at the |
| -// top, and changing into |middle_color| and then over to |bottom_color| as |
| -// you go further down. |
| -void PaintVerticalDivider(gfx::Canvas* canvas, |
| - int x, |
| - int height, |
| - int vertical_padding, |
| - SkColor top_color, |
| - SkColor middle_color, |
| - SkColor bottom_color) { |
| - // Draw the upper half of the divider. |
| - SkPaint paint; |
| - paint.setShader(gfx::CreateGradientShader( |
| - vertical_padding + 1, height / 2, top_color, middle_color)); |
| - SkRect rc = { SkIntToScalar(x), |
| - SkIntToScalar(vertical_padding + 1), |
| - SkIntToScalar(x + 1), |
| - SkIntToScalar(height / 2) }; |
| - canvas->sk_canvas()->drawRect(rc, paint); |
| - |
| - // Draw the lower half of the divider. |
| - SkPaint paint_down; |
| - paint_down.setShader(gfx::CreateGradientShader( |
| - height / 2, height - vertical_padding, middle_color, bottom_color)); |
| - SkRect rc_down = { SkIntToScalar(x), |
| - SkIntToScalar(height / 2), |
| - SkIntToScalar(x + 1), |
| - SkIntToScalar(height - vertical_padding) }; |
| - canvas->sk_canvas()->drawRect(rc_down, paint_down); |
| -} |
| - |
| class BookmarkBarView::ButtonSeparatorView : public views::View { |
| public: |
| ButtonSeparatorView() {} |
| ~ButtonSeparatorView() override {} |
| void OnPaint(gfx::Canvas* canvas) override { |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - gfx::ScopedCanvas scoped_canvas(canvas); |
| - // 1px wide at all scale factors. If there is an uneven amount of padding |
| - // left over, place the extra pixel on the outside, i.e. away from the |
| - // "Other bookmarks" folder. |
| - const float scale = canvas->UndoDeviceScaleFactor(); |
| - const gfx::RectF scaled_bounds = |
| - gfx::ScaleRect(gfx::RectF(bounds()), scale); |
| - |
| - const int kLineThickness = 1; |
| - const float fractional_x = (scaled_bounds.width() - kLineThickness) / 2.f; |
| - const int x = base::i18n::IsRTL() ? std::floor(fractional_x) |
| - : std::ceil(fractional_x); |
| - |
| - const int height = gfx::kFaviconSize * scale; |
| - const int top_y = (scaled_bounds.height() - height) / 2; |
| - canvas->DrawLine(gfx::Point(x, top_y), gfx::Point(x, top_y + height), |
| - GetThemeProvider()->GetColor( |
| - ThemeProperties::COLOR_TOOLBAR_VERTICAL_SEPARATOR)); |
| - } else { |
| - PaintVerticalDivider( |
| - canvas, kSeparatorStartX, height(), 1, kEdgeDividerColor, |
| - kMiddleDividerColor, |
| - GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
| - } |
| + gfx::ScopedCanvas scoped_canvas(canvas); |
| + // 1px wide at all scale factors. If there is an uneven amount of padding |
| + // left over, place the extra pixel on the outside, i.e. away from the |
| + // "Other bookmarks" folder. |
| + const float scale = canvas->UndoDeviceScaleFactor(); |
| + const gfx::RectF scaled_bounds = |
| + gfx::ScaleRect(gfx::RectF(bounds()), scale); |
| + |
| + const int kLineThickness = 1; |
| + const float fractional_x = (scaled_bounds.width() - kLineThickness) / 2.f; |
| + const int x = base::i18n::IsRTL() ? std::floor(fractional_x) |
| + : std::ceil(fractional_x); |
| + |
| + const int height = gfx::kFaviconSize * scale; |
| + const int top_y = (scaled_bounds.height() - height) / 2; |
| + canvas->DrawLine(gfx::Point(x, top_y), gfx::Point(x, top_y + height), |
| + GetThemeProvider()->GetColor( |
| + ThemeProperties::COLOR_TOOLBAR_VERTICAL_SEPARATOR)); |
| } |
| gfx::Size GetPreferredSize() const override { |
| // We get the full height of the bookmark bar, so that the height returned |
| // here doesn't matter. |
| - return gfx::Size(kSeparatorWidth[ui::MaterialDesignController::GetMode()], |
| - 1); |
| + return gfx::Size(kSeparatorWidth, 1); |
| } |
| void GetAccessibleState(ui::AXViewState* state) override { |
| @@ -601,34 +529,32 @@ class BookmarkBarView::ButtonSeparatorView : public views::View { |
| const char BookmarkBarView::kViewClassName[] = "BookmarkBarView"; |
| BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
| - : page_navigator_(NULL), |
| - managed_(NULL), |
| - bookmark_menu_(NULL), |
| - bookmark_drop_menu_(NULL), |
| - other_bookmarks_button_(NULL), |
| - managed_bookmarks_button_(NULL), |
| - supervised_bookmarks_button_(NULL), |
| - apps_page_shortcut_(NULL), |
| - overflow_button_(NULL), |
| - instructions_(NULL), |
| - bookmarks_separator_view_(NULL), |
| + : page_navigator_(nullptr), |
| + managed_(nullptr), |
| + bookmark_menu_(nullptr), |
| + bookmark_drop_menu_(nullptr), |
| + other_bookmarks_button_(nullptr), |
| + managed_bookmarks_button_(nullptr), |
| + supervised_bookmarks_button_(nullptr), |
| + apps_page_shortcut_(nullptr), |
| + overflow_button_(nullptr), |
| + instructions_(nullptr), |
| + bookmarks_separator_view_(nullptr), |
| browser_(browser), |
| browser_view_(browser_view), |
| infobar_visible_(false), |
| size_animation_(this), |
| - throbbing_view_(NULL), |
| + throbbing_view_(nullptr), |
| bookmark_bar_state_(BookmarkBar::SHOW), |
| animating_detached_(false), |
| show_folder_method_factory_(this) { |
| set_id(VIEW_ID_BOOKMARK_BAR); |
| Init(); |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - // Don't let the bookmarks show on top of the location bar while animating. |
| - SetPaintToLayer(true); |
| - layer()->SetMasksToBounds(true); |
| - layer()->SetFillsBoundsOpaquely(false); |
| - } |
| + // Don't let the bookmarks show on top of the location bar while animating. |
| + SetPaintToLayer(true); |
| + layer()->SetMasksToBounds(true); |
| + layer()->SetFillsBoundsOpaquely(false); |
| size_animation_.Reset(1); |
| } |
| @@ -640,12 +566,12 @@ BookmarkBarView::~BookmarkBarView() { |
| // It's possible for the menu to outlive us, reset the observer to make sure |
| // it doesn't have a reference to us. |
| if (bookmark_menu_) { |
| - bookmark_menu_->set_observer(NULL); |
| - bookmark_menu_->SetPageNavigator(NULL); |
| + bookmark_menu_->set_observer(nullptr); |
| + bookmark_menu_->SetPageNavigator(nullptr); |
| bookmark_menu_->clear_bookmark_bar(); |
| } |
| if (context_menu_.get()) |
| - context_menu_->SetPageNavigator(NULL); |
| + context_menu_->SetPageNavigator(nullptr); |
| StopShowFolderDropMenuTimer(); |
| } |
| @@ -694,7 +620,7 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( |
| *model_start_index = 0; |
| if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height()) |
| - return NULL; |
| + return nullptr; |
| gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); |
| @@ -732,7 +658,7 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( |
| return model_->other_node(); |
| } |
| - return NULL; |
| + return nullptr; |
| } |
| views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
| @@ -747,7 +673,7 @@ views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
| return overflow_button_; |
| int index = model_->bookmark_bar_node()->GetIndexOf(node); |
| if (index == -1 || !node->is_folder()) |
| - return NULL; |
| + return nullptr; |
| return static_cast<views::MenuButton*>(child_at(index)); |
| } |
| @@ -761,15 +687,15 @@ void BookmarkBarView::GetAnchorPositionForButton( |
| } |
| views::MenuItemView* BookmarkBarView::GetMenu() { |
| - return bookmark_menu_ ? bookmark_menu_->menu() : NULL; |
| + return bookmark_menu_ ? bookmark_menu_->menu() : nullptr; |
| } |
| views::MenuItemView* BookmarkBarView::GetContextMenu() { |
| - return bookmark_menu_ ? bookmark_menu_->context_menu() : NULL; |
| + return bookmark_menu_ ? bookmark_menu_->context_menu() : nullptr; |
| } |
| views::MenuItemView* BookmarkBarView::GetDropMenu() { |
| - return bookmark_drop_menu_ ? bookmark_drop_menu_->menu() : NULL; |
| + return bookmark_drop_menu_ ? bookmark_drop_menu_->menu() : nullptr; |
| } |
| void BookmarkBarView::StopThrobbing(bool immediate) { |
| @@ -778,7 +704,7 @@ void BookmarkBarView::StopThrobbing(bool immediate) { |
| // If not immediate, cycle through 2 more complete cycles. |
| throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
| - throbbing_view_ = NULL; |
| + throbbing_view_ = nullptr; |
| } |
| // static |
| @@ -888,7 +814,7 @@ gfx::Size BookmarkBarView::GetMinimumSize() const { |
| // Bookmarks" folder, along with appropriate margins and button padding. |
| // It should also contain the Managed and/or Supervised Bookmarks folders, |
| // if they are visible. |
| - int width = GetHorizontalMargin(); |
| + int width = kHorizontalMargin; |
| int height = GetPreferredHeight(); |
| if (IsDetached()) { |
| @@ -931,10 +857,10 @@ void BookmarkBarView::Layout() { |
| if (!model_) |
| return; |
| - int x = GetHorizontalMargin(); |
| + int x = kHorizontalMargin; |
| int top_margin = IsDetached() ? kDetachedTopMargin : 0; |
| int y = top_margin; |
| - int width = View::width() - 2 * GetHorizontalMargin(); |
| + int width = View::width() - 2 * kHorizontalMargin; |
| int preferred_height = GetPreferredHeight(); |
| int height = preferred_height - kBottomMargin; |
| int separator_margin = kSeparatorMargin; |
| @@ -1090,7 +1016,7 @@ void BookmarkBarView::PaintChildren(const ui::PaintContext& context) { |
| int h = height(); |
| if (index == GetBookmarkButtonCount()) { |
| if (index == 0) { |
| - x = GetHorizontalMargin(); |
| + x = kHorizontalMargin; |
| } else { |
| x = GetBookmarkButton(index - 1)->x() + |
| GetBookmarkButton(index - 1)->width(); |
| @@ -1113,7 +1039,9 @@ void BookmarkBarView::PaintChildren(const ui::PaintContext& context) { |
| ui::PaintRecorder recorder(context, size()); |
| // TODO(sky/glen): make me pretty! |
| - recorder.canvas()->FillRect(indicator_bounds, kDropIndicatorColor); |
| + recorder.canvas()->FillRect( |
| + indicator_bounds, |
| + GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); |
| } |
| } |
| @@ -1274,13 +1202,13 @@ void BookmarkBarView::GetAccessibleState(ui::AXViewState* state) { |
| } |
| void BookmarkBarView::AnimationProgressed(const gfx::Animation* animation) { |
| - // |browser_view_| can be NULL during tests. |
| + // |browser_view_| can be nullptr during tests. |
|
Peter Kasting
2016/09/22 03:23:27
Nit: Prefer "null" to "nullptr" in comments, it ju
Evan Stade
2016/09/22 14:35:27
Done.
|
| if (browser_view_) |
| browser_view_->ToolbarSizeChanged(true); |
| } |
| void BookmarkBarView::AnimationEnded(const gfx::Animation* animation) { |
| - // |browser_view_| can be NULL during tests. |
| + // |browser_view_| can be nullptr during tests. |
| if (browser_view_) { |
| browser_view_->ToolbarSizeChanged(false); |
| SchedulePaint(); |
| @@ -1290,9 +1218,9 @@ void BookmarkBarView::AnimationEnded(const gfx::Animation* animation) { |
| void BookmarkBarView::BookmarkMenuControllerDeleted( |
| BookmarkMenuController* controller) { |
| if (controller == bookmark_menu_) |
| - bookmark_menu_ = NULL; |
| + bookmark_menu_ = nullptr; |
| else if (controller == bookmark_drop_menu_) |
| - bookmark_drop_menu_ = NULL; |
| + bookmark_drop_menu_ = nullptr; |
| } |
| void BookmarkBarView::OnImportBookmarks() { |
| @@ -1348,7 +1276,7 @@ void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| NOTREACHED(); |
| // Do minimal cleanup, presumably we'll be deleted shortly. |
| model_->RemoveObserver(this); |
| - model_ = NULL; |
| + model_ = nullptr; |
| } |
| void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, |
| @@ -1624,10 +1552,9 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source, |
| void BookmarkBarView::Init() { |
| // Note that at this point we're not in a hierarchy so GetThemeProvider() will |
| - // return NULL. When we're inserted into a hierarchy, we'll call |
| + // return nullptr. When we're inserted into a hierarchy, we'll call |
| // UpdateAppearanceForTheme(), which will set the appropriate colors for all |
| - // the objects |
| - // added in this function. |
| + // the objects added in this function. |
| // Child views are traversed in the order they are added. Make sure the order |
| // they are added matches the visual order. |