mac: Implement SetProgressBar API.
This commit is contained in:
parent
b5e82dac6f
commit
c5e0b65cc7
2 changed files with 67 additions and 0 deletions
|
@ -65,6 +65,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
virtual bool IsDocumentEdited() OVERRIDE;
|
virtual bool IsDocumentEdited() OVERRIDE;
|
||||||
virtual bool HasModalDialog() OVERRIDE;
|
virtual bool HasModalDialog() OVERRIDE;
|
||||||
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
||||||
|
virtual void SetProgressBar(double progress) OVERRIDE;
|
||||||
|
|
||||||
// Returns true if |point| in local Cocoa coordinate system falls within
|
// Returns true if |point| in local Cocoa coordinate system falls within
|
||||||
// the draggable region.
|
// the draggable region.
|
||||||
|
|
|
@ -193,6 +193,39 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface AtomProgressBar : NSProgressIndicator
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation AtomProgressBar
|
||||||
|
|
||||||
|
- (void)drawRect:(NSRect)dirtyRect {
|
||||||
|
if (self.style != NSProgressIndicatorBarStyle)
|
||||||
|
return;
|
||||||
|
// Draw edges of rounded rect.
|
||||||
|
NSRect rect = NSInsetRect([self bounds], 1.0, 1.0);
|
||||||
|
CGFloat radius = rect.size.height / 2;
|
||||||
|
NSBezierPath* bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
|
||||||
|
[bezier_path setLineWidth:2.0];
|
||||||
|
[[NSColor grayColor] set];
|
||||||
|
[bezier_path stroke];
|
||||||
|
|
||||||
|
// Fill the rounded rect.
|
||||||
|
rect = NSInsetRect(rect, 2.0, 2.0);
|
||||||
|
radius = rect.size.height / 2;
|
||||||
|
bezier_path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
|
||||||
|
[bezier_path setLineWidth:1.0];
|
||||||
|
[bezier_path addClip];
|
||||||
|
|
||||||
|
// Calculate the progress width.
|
||||||
|
rect.size.width = floor(rect.size.width * ([self doubleValue] / [self maxValue]));
|
||||||
|
|
||||||
|
// Fill the progress bar with color blue.
|
||||||
|
[[NSColor colorWithSRGBRed:0.2 green:0.6 blue:1 alpha:1] set];
|
||||||
|
NSRectFill(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||||
|
@ -517,6 +550,39 @@ gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
|
||||||
return window_;
|
return window_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::SetProgressBar(double progress) {
|
||||||
|
NSDockTile* dock_tile = [NSApp dockTile];
|
||||||
|
|
||||||
|
// For the first time API invoked, we need to create a ContentView in DockTile.
|
||||||
|
if (dock_tile.contentView == NULL) {
|
||||||
|
NSImageView* image_view = [[NSImageView alloc] init];
|
||||||
|
[image_view setImage:[NSApp applicationIconImage]];
|
||||||
|
[dock_tile setContentView:image_view];
|
||||||
|
|
||||||
|
NSProgressIndicator* progress_indicator = [[AtomProgressBar alloc]
|
||||||
|
initWithFrame:NSMakeRect(0.0f, 0.0f, dock_tile.size.width, 15.0)];
|
||||||
|
[progress_indicator setStyle:NSProgressIndicatorBarStyle];
|
||||||
|
[progress_indicator setIndeterminate:NO];
|
||||||
|
[progress_indicator setBezeled:YES];
|
||||||
|
[progress_indicator setMinValue:0];
|
||||||
|
[progress_indicator setMaxValue:1];
|
||||||
|
[progress_indicator setHidden:NO];
|
||||||
|
[image_view addSubview:progress_indicator];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSProgressIndicator* progress_indicator =
|
||||||
|
static_cast<NSProgressIndicator*>([[[dock_tile contentView] subviews]
|
||||||
|
objectAtIndex:0]);
|
||||||
|
if (progress < 0) {
|
||||||
|
[progress_indicator setHidden:YES];
|
||||||
|
} else if (progress > 1) {
|
||||||
|
[progress_indicator setIndeterminate:YES];
|
||||||
|
} else {
|
||||||
|
[progress_indicator setDoubleValue:progress];
|
||||||
|
}
|
||||||
|
[dock_tile display];
|
||||||
|
}
|
||||||
|
|
||||||
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
||||||
if (!draggable_region_)
|
if (!draggable_region_)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue