Skip to content

Commit

Permalink
Misc. cleanup:
Browse files Browse the repository at this point in the history
* Scope constants/variables as narrowly as possible
* Don't override virtual methods unnecessarily
* Minor comment improvements
* Don't inline not-normally-inlined methods in non-test code
* Use {} where required
* Eliminate leftover forward-decl in MaximizeBubbleController (oops)
* Fix indenting & wrapping

BUG=none
TEST=none
R=sky@chromium.org

Review URL: https://codereview.chromium.org/80043002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236628 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pkasting@chromium.org committed Nov 21, 2013
1 parent 1168033 commit 6f261db
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 107 deletions.
68 changes: 30 additions & 38 deletions ash/system/tray/tray_popup_label_button_border.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,50 @@
namespace ash {
namespace internal {

namespace {

const int kTrayPopupLabelButtonPaddingHorizontal = 16;
const int kTrayPopupLabelButtonPaddingVertical = 8;

const int kTrayPopupLabelButtonBorderImagesNormal[] = {
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
};

const int kTrayPopupLabelButtonBorderImagesHovered[] = {
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
};

} // namespace

TrayPopupLabelButtonBorder::TrayPopupLabelButtonBorder()
: LabelButtonBorder(views::Button::STYLE_TEXTBUTTON) {
const int kTrayPopupLabelButtonBorderImagesNormal[] = {
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
};
SetPainter(false, views::Button::STATE_NORMAL,
views::Painter::CreateImageGridPainter(
kTrayPopupLabelButtonBorderImagesNormal));
SetPainter(false, views::Button::STATE_DISABLED,
views::Painter::CreateImageGridPainter(
kTrayPopupLabelButtonBorderImagesNormal));

const int kTrayPopupLabelButtonBorderImagesHovered[] = {
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
};
SetPainter(false, views::Button::STATE_HOVERED,
views::Painter::CreateImageGridPainter(
kTrayPopupLabelButtonBorderImagesHovered));
SetPainter(false, views::Button::STATE_PRESSED,
views::Painter::CreateImageGridPainter(
kTrayPopupLabelButtonBorderImagesHovered));

const int kTrayPopupLabelButtonPaddingHorizontal = 16;
const int kTrayPopupLabelButtonPaddingVertical = 8;
set_insets(gfx::Insets(kTrayPopupLabelButtonPaddingVertical,
kTrayPopupLabelButtonPaddingHorizontal,
kTrayPopupLabelButtonPaddingVertical,
kTrayPopupLabelButtonPaddingHorizontal));
}

TrayPopupLabelButtonBorder::~TrayPopupLabelButtonBorder() {}
Expand Down Expand Up @@ -98,12 +97,5 @@ void TrayPopupLabelButtonBorder::Paint(const views::View& view,
}
}

gfx::Insets TrayPopupLabelButtonBorder::GetInsets() const {
return gfx::Insets(kTrayPopupLabelButtonPaddingVertical,
kTrayPopupLabelButtonPaddingHorizontal,
kTrayPopupLabelButtonPaddingVertical,
kTrayPopupLabelButtonPaddingHorizontal);
}

} // namespace internal
} // namespace ash
3 changes: 1 addition & 2 deletions ash/system/tray/tray_popup_label_button_border.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ class TrayPopupLabelButtonBorder : public views::LabelButtonBorder {
TrayPopupLabelButtonBorder();
virtual ~TrayPopupLabelButtonBorder();

// Overridden from views::LabelButtonBorder.
// views::LabelButtonBorder:
virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE;
virtual gfx::Insets GetInsets() const OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(TrayPopupLabelButtonBorder);
Expand Down
53 changes: 29 additions & 24 deletions ash/wm/caption_buttons/bubble_contents_button_row.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ namespace ash {
// BubbleDialogButton ---------------------------------------------------------

// The image button gets overridden to be able to capture mouse hover events.
// The constructor also assigns all button states and
// The constructor also assigns all button states and adds |this| as a child of
// |button_row|.
class BubbleDialogButton : public views::ImageButton {
public:
explicit BubbleDialogButton(
BubbleContentsButtonRow* button_row_listener,
int normal_image,
int hovered_image,
int pressed_image);
virtual ~BubbleDialogButton() {}

// CustomButton overrides:
explicit BubbleDialogButton(BubbleContentsButtonRow* button_row,
int normal_image,
int hovered_image,
int pressed_image);
virtual ~BubbleDialogButton();

// views::ImageButton:
virtual void OnMouseCaptureLost() OVERRIDE;
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
Expand Down Expand Up @@ -57,6 +57,9 @@ BubbleDialogButton::BubbleDialogButton(
button_row->AddChildView(this);
}

BubbleDialogButton::~BubbleDialogButton() {
}

void BubbleDialogButton::OnMouseCaptureLost() {
button_row_->ButtonHovered(NULL);
views::ImageButton::OnMouseCaptureLost();
Expand Down Expand Up @@ -114,43 +117,45 @@ BubbleContentsButtonRow::BubbleContentsButtonRow(
}
}

// Overridden from ButtonListener.
BubbleContentsButtonRow::~BubbleContentsButtonRow() {
}

void BubbleContentsButtonRow::ButtonPressed(views::Button* sender,
const ui::Event& event) {
// While shutting down, the connection to the owner might already be broken.
if (!bubble_->controller())
return;
if (sender == left_button_)
if (sender == left_button_) {
bubble_->controller()->OnButtonClicked(
bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_LEFT ?
(bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_LEFT) ?
SNAP_RESTORE : SNAP_LEFT);
else if (sender == minimize_button_)
} else if (sender == minimize_button_) {
bubble_->controller()->OnButtonClicked(SNAP_MINIMIZE);
else if (sender == right_button_)
} else {
DCHECK(sender == right_button_);
bubble_->controller()->OnButtonClicked(
bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_RIGHT ?
(bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_RIGHT) ?
SNAP_RESTORE : SNAP_RIGHT);
else
NOTREACHED() << "Unknown button pressed.";
}
}

// Called from BubbleDialogButton.
void BubbleContentsButtonRow::ButtonHovered(BubbleDialogButton* sender) {
// While shutting down, the connection to the owner might already be broken.
if (!bubble_->controller())
return;
if (sender == left_button_)
if (sender == left_button_) {
bubble_->controller()->OnButtonHover(
bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_LEFT ?
(bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_LEFT) ?
SNAP_RESTORE : SNAP_LEFT);
else if (sender == minimize_button_)
} else if (sender == minimize_button_) {
bubble_->controller()->OnButtonHover(SNAP_MINIMIZE);
else if (sender == right_button_)
} else if (sender == right_button_) {
bubble_->controller()->OnButtonHover(
bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_RIGHT ?
(bubble_->controller()->maximize_type() == FRAME_STATE_SNAP_RIGHT) ?
SNAP_RESTORE : SNAP_RIGHT);
else
} else {
bubble_->controller()->OnButtonHover(SNAP_NONE);
}
}

views::CustomButton* BubbleContentsButtonRow::GetButtonForUnitTest(
Expand Down
8 changes: 4 additions & 4 deletions ash/wm/caption_buttons/bubble_contents_button_row.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ namespace ash {
class BubbleDialogButton;
class MaximizeBubbleControllerBubble;

// A class that creates all buttons and put them into a view.
// A class that creates all buttons and puts them into a view.
class BubbleContentsButtonRow : public views::View,
public views::ButtonListener {
public:
explicit BubbleContentsButtonRow(MaximizeBubbleControllerBubble* bubble);
virtual ~BubbleContentsButtonRow();

virtual ~BubbleContentsButtonRow() {}

// Overridden from ButtonListener.
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;

// Called from BubbleDialogButton.
void ButtonHovered(BubbleDialogButton* sender);

Expand Down
2 changes: 0 additions & 2 deletions ash/wm/caption_buttons/maximize_bubble_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class MaximizeBubbleControllerBubble;
// A class which shows a helper UI for the maximize button after a delay.
class ASH_EXPORT MaximizeBubbleController {
public:
class Bubble;

MaximizeBubbleController(FrameMaximizeButton* frame_maximize_button,
MaximizeBubbleFrameState maximize_type,
int appearance_delay_ms);
Expand Down
Loading

0 comments on commit 6f261db

Please sign in to comment.