Commit a0aab5b4 authored by gajendra.n's avatar gajendra.n Committed by Commit bot

Color picker window should not have a minimize button.

Adding CanMinimize() (like CanMaximize()) function to WidgetDelegate class.
So that ColorChooserView or any other view inheriting WidgetDelegate, can
decide whether its window can show minimize button.

BUG=365768

R=sadrul@chromium.org

TEST=
1. Go to a page with <input type=color>. Here is one http://jsbin.com/yotasure/1
2. Click on the color input button to bring up the color picker window and observe
3. Color picker window should not have minimize button.

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

Cr-Commit-Position: refs/heads/master@{#295919}
parent bbe75265
......@@ -437,6 +437,10 @@ void ColorChooserView::OnSaturationValueChosen(SkScalar saturation,
textfield_->SetText(GetColorText(color));
}
bool ColorChooserView::CanMinimize() const {
return false;
}
View* ColorChooserView::GetInitiallyFocusedView() {
return textfield_;
}
......
......@@ -48,6 +48,7 @@ class VIEWS_EXPORT ColorChooserView : public WidgetDelegateView,
class SelectedColorPatchView;
// WidgetDelegate overrides:
virtual bool CanMinimize() const OVERRIDE;
virtual View* GetInitiallyFocusedView() OVERRIDE;
virtual ui::ModalType GetModalType() const OVERRIDE;
virtual void WindowClosing() OVERRIDE;
......
......@@ -51,6 +51,10 @@ bool WidgetDelegate::CanMaximize() const {
return false;
}
bool WidgetDelegate::CanMinimize() const {
return false;
}
bool WidgetDelegate::CanActivate() const {
return can_activate_;
}
......
......@@ -58,6 +58,9 @@ class VIEWS_EXPORT WidgetDelegate {
// Returns true if the window can ever be maximized.
virtual bool CanMaximize() const;
// Returns true if the window can ever be minimized.
virtual bool CanMinimize() const;
// Returns true if the window can be activated.
virtual bool CanActivate() const;
......
......@@ -599,6 +599,13 @@ ImageButton* CustomFrameView::GetImageButton(views::FrameButton frame_button) {
switch (frame_button) {
case views::FRAME_BUTTON_MINIMIZE: {
button = minimize_button_;
// If we should not show the minimize button, then we return NULL as we
// don't want this button to become visible and to be laid out.
bool should_show = frame_->widget_delegate()->CanMinimize();
button->SetVisible(should_show);
if (!should_show)
return NULL;
break;
}
case views::FRAME_BUTTON_MAXIMIZE: {
......
......@@ -16,25 +16,33 @@ namespace views {
namespace {
// Allows for the control of whether or not the widget can maximize or not.
// This can be set after initial setup in order to allow testing of both forms
// of delegates. By default this can maximize.
class MaximizeStateControlDelegate : public WidgetDelegateView {
// Allows for the control of whether or not the widget can minimize/maximize or
// not. This can be set after initial setup in order to allow testing of both
// forms of delegates. By default this can minimize and maximize.
class MinimizeAndMaximizeStateControlDelegate : public WidgetDelegateView {
public:
MaximizeStateControlDelegate() : can_maximize_(true) {}
virtual ~MaximizeStateControlDelegate() {}
MinimizeAndMaximizeStateControlDelegate()
: can_maximize_(true),
can_minimize_(true) {}
virtual ~MinimizeAndMaximizeStateControlDelegate() {}
void set_can_maximize(bool can_maximize) {
can_maximize_ = can_maximize;
}
void set_can_minimize(bool can_minimize) {
can_minimize_ = can_minimize;
}
// WidgetDelegate:
virtual bool CanMaximize() const OVERRIDE { return can_maximize_; }
virtual bool CanMinimize() const OVERRIDE { return can_minimize_; }
private:
bool can_maximize_;
bool can_minimize_;
DISALLOW_COPY_AND_ASSIGN(MaximizeStateControlDelegate);
DISALLOW_COPY_AND_ASSIGN(MinimizeAndMaximizeStateControlDelegate);
};
} // namespace
......@@ -48,8 +56,9 @@ class CustomFrameViewTest : public ViewsTestBase {
return custom_frame_view_;
}
MaximizeStateControlDelegate* maximize_state_control_delegate() {
return maximize_state_control_delegate_;
MinimizeAndMaximizeStateControlDelegate*
minimize_and_maximize_state_control_delegate() {
return minimize_and_maximize_state_control_delegate_;
}
Widget* widget() {
......@@ -100,8 +109,9 @@ class CustomFrameViewTest : public ViewsTestBase {
// Owned by |widget_|
CustomFrameView* custom_frame_view_;
// Delegate of |widget_| which controls maximizing
MaximizeStateControlDelegate* maximize_state_control_delegate_;
// Delegate of |widget_| which controls minimizing and maximizing
MinimizeAndMaximizeStateControlDelegate*
minimize_and_maximize_state_control_delegate_;
DISALLOW_COPY_AND_ASSIGN(CustomFrameViewTest);
};
......@@ -109,10 +119,11 @@ class CustomFrameViewTest : public ViewsTestBase {
void CustomFrameViewTest::SetUp() {
ViewsTestBase::SetUp();
maximize_state_control_delegate_ = new MaximizeStateControlDelegate;
minimize_and_maximize_state_control_delegate_ =
new MinimizeAndMaximizeStateControlDelegate;
widget_ = new Widget;
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
params.delegate = maximize_state_control_delegate_;
params.delegate = minimize_and_maximize_state_control_delegate_;
params.remove_standard_frame = true;
widget_->Init(params);
......@@ -209,7 +220,8 @@ TEST_F(CustomFrameViewTest, MaximizeRevealsRestoreButton) {
TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) {
Widget* parent = widget();
CustomFrameView* view = custom_frame_view();
MaximizeStateControlDelegate* delegate = maximize_state_control_delegate();
MinimizeAndMaximizeStateControlDelegate* delegate =
minimize_and_maximize_state_control_delegate();
delegate->set_can_maximize(false);
view->Init(parent);
......@@ -220,6 +232,22 @@ TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) {
EXPECT_FALSE(maximize_button()->visible());
}
// Tests that when the parent cannot minimize that the minimize button is not
// visible
TEST_F(CustomFrameViewTest, CannotMinimizeHidesButton) {
Widget* parent = widget();
CustomFrameView* view = custom_frame_view();
MinimizeAndMaximizeStateControlDelegate* delegate =
minimize_and_maximize_state_control_delegate();
delegate->set_can_minimize(false);
view->Init(parent);
parent->SetBounds(gfx::Rect(0, 0, 300, 100));
parent->Show();
EXPECT_FALSE(minimize_button()->visible());
}
// Tests that when maximized that the edge button has an increased width.
TEST_F(CustomFrameViewTest, LargerEdgeButtonsWhenMaximized) {
Widget* parent = widget();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment