blob: 511000dc7855938ceab31694149ddf9e2125e0e4 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#import "base/mac/scoped_nsobject.h"
#include "content/public/browser/color_chooser.h"
#include "content/public/browser/web_contents.h"
class ColorChooserMac;
// A Listener class to act as a event target for NSColorPanel and send
// the results to the C++ class, ColorChooserMac.
@interface ColorPanelCocoa : NSObject<NSWindowDelegate> {
// We don't call DidChooseColor if the change wasn't caused by the user
// interacting with the panel.
BOOL nonUserChange_;
ColorChooserMac* chooser_; // weak, owns this
- (id)initWithChooser:(ColorChooserMac*)chooser;
// Called from NSColorPanel.
- (void)didChooseColor:(NSColorPanel*)panel;
// Sets color to the NSColorPanel as a non user change.
- (void)setColor:(NSColor*)color;
class ColorChooserMac : public content::ColorChooser {
// Returns a ColorChooserMac instance owned by the ColorChooserMac class -
// call End() when done to free it. Each call to Open() returns a new
// instance after freeing the previous one (i.e. it does not reuse the
// previous instance even if it still exists).
static ColorChooserMac* Open(content::WebContents* web_contents,
SkColor initial_color);
// Called from ColorPanelCocoa.
void DidChooseColorInColorPanel(SkColor color);
void DidCloseColorPabel();
// Set the color programmatically.
void SetSelectedColor(SkColor color) override;
// Call when done with the ColorChooserMac.
void End() override;
ColorChooserMac(content::WebContents* tab, SkColor initial_color);
~ColorChooserMac() override;
static ColorChooserMac* current_color_chooser_;
// The web contents invoking the color chooser. No ownership because it will
// outlive this class.
content::WebContents* web_contents_;
base::scoped_nsobject<ColorPanelCocoa> panel_;