ui: override default theme

This commit overide style for tree items rendering, to fit with wireframes.
It adds a new Highlight shadow, new item separator, new Selected style.
Items can also have an array of "contextual views" that will be rendered only
on mouse hovers events.
It also introduce support for Ring official colors.

Issue: #79400, #79398
Change-Id: I8d227955f9afe25240b1ece991c57a3cbf996474
diff --git a/src/views/ContextualTableCellView.h b/src/views/ContextualTableCellView.h
new file mode 100644
index 0000000..ee833ff
--- /dev/null
+++ b/src/views/ContextualTableCellView.h
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (C) 2015 Savoir-faire Linux Inc.
+ *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface ContextualTableCellView : NSTableCellView
+
+/**
+ * List of subviews to hide/show when mouse is tracked
+ */
+@property (nonatomic) NSMutableArray* contextualsControls;
+
+@end
diff --git a/src/views/ContextualTableCellView.mm b/src/views/ContextualTableCellView.mm
new file mode 100644
index 0000000..9f844bc
--- /dev/null
+++ b/src/views/ContextualTableCellView.mm
@@ -0,0 +1,69 @@
+/*
+ *  Copyright (C) 2015 Savoir-faire Linux Inc.
+ *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#import "ContextualTableCellView.h"
+
+@interface ContextualTableCellView()
+
+@property NSTrackingArea *trackingArea;
+
+@end
+
+@implementation ContextualTableCellView
+
+
+- (void)updateTrackingAreas {
+    [super updateTrackingAreas];
+    [self ensureTrackingArea];
+    if (![[self trackingAreas] containsObject:_trackingArea]) {
+        [self addTrackingArea:_trackingArea];
+    }
+}
+
+- (void)ensureTrackingArea {
+    if (_trackingArea == nil) {
+        _trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
+                                                    options:NSTrackingInVisibleRect
+                        | NSTrackingActiveAlways
+                        | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
+    }
+}
+
+- (void)prepareForReuse
+{
+    for (NSView* item in self.contextualsControls) {
+        [item setHidden:YES];
+    }
+}
+
+- (void)mouseEntered:(NSEvent *)theEvent
+{
+    for (NSView* item in self.contextualsControls) {
+        [item setHidden:NO];
+    }
+}
+
+- (void)mouseExited:(NSEvent *)theEvent
+{
+    for (NSView* item in self.contextualsControls) {
+        [item setHidden:YES];
+    }
+}
+
+@end
diff --git a/src/views/HoverTableRowView.h b/src/views/HoverTableRowView.h
new file mode 100644
index 0000000..e477087
--- /dev/null
+++ b/src/views/HoverTableRowView.h
@@ -0,0 +1,61 @@
+/*
+     File: HoverTableRowView.h
+ Abstract: Custom NSTableRowView class for custom drawing and mouse tracking feedback via NSTrackingArea
+  Version: 1.1
+
+ Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple
+ Inc. ("Apple") in consideration of your agreement to the following
+ terms, and your use, installation, modification or redistribution of
+ this Apple software constitutes acceptance of these terms.  If you do
+ not agree with these terms, please do not use, install, modify or
+ redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and
+ subject to these terms, Apple grants you a personal, non-exclusive
+ license, under Apple's copyrights in this original Apple software (the
+ "Apple Software"), to use, reproduce, modify and redistribute the Apple
+ Software, with or without modifications, in source and/or binary forms;
+ provided that if you redistribute the Apple Software in its entirety and
+ without modifications, you must retain this notice and the following
+ text and disclaimers in all such redistributions of the Apple Software.
+ Neither the name, trademarks, service marks or logos of Apple Inc. may
+ be used to endorse or promote products derived from the Apple Software
+ without specific prior written permission from Apple.  Except as
+ expressly stated in this notice, no other rights or licenses, express or
+ implied, are granted by Apple herein, including but not limited to any
+ patent rights that may be infringed by your derivative works or by other
+ works in which the Apple Software may be incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
+ MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+ OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+ MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+ STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ Copyright (C) 2012 Apple Inc. All Rights Reserved.
+
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface HoverTableRowView : NSTableRowView {
+@private
+    BOOL mouseInside;
+    NSTrackingArea *trackingArea;
+}
+
+@property BOOL highlightable;
+
+@end
+
+// Used by the HoverTableRowView and the RingOutlineView
+void DrawSeparatorInRect(NSRect rect);
diff --git a/src/views/HoverTableRowView.mm b/src/views/HoverTableRowView.mm
new file mode 100644
index 0000000..05a7f00
--- /dev/null
+++ b/src/views/HoverTableRowView.mm
@@ -0,0 +1,203 @@
+/*
+     File: HoverTableRowView.m
+ Abstract: Custom NSTableRowView class for custom drawing and mouse tracking feedback via NSTrackingArea
+  Version: 1.1
+
+ Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple
+ Inc. ("Apple") in consideration of your agreement to the following
+ terms, and your use, installation, modification or redistribution of
+ this Apple software constitutes acceptance of these terms.  If you do
+ not agree with these terms, please do not use, install, modify or
+ redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and
+ subject to these terms, Apple grants you a personal, non-exclusive
+ license, under Apple's copyrights in this original Apple software (the
+ "Apple Software"), to use, reproduce, modify and redistribute the Apple
+ Software, with or without modifications, in source and/or binary forms;
+ provided that if you redistribute the Apple Software in its entirety and
+ without modifications, you must retain this notice and the following
+ text and disclaimers in all such redistributions of the Apple Software.
+ Neither the name, trademarks, service marks or logos of Apple Inc. may
+ be used to endorse or promote products derived from the Apple Software
+ without specific prior written permission from Apple.  Except as
+ expressly stated in this notice, no other rights or licenses, express or
+ implied, are granted by Apple herein, including but not limited to any
+ patent rights that may be infringed by your derivative works or by other
+ works in which the Apple Software may be incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
+ MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+ OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+ MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+ STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ Copyright (C) 2012 Apple Inc. All Rights Reserved.
+
+ */
+
+#import "HoverTableRowView.h"
+
+#import "NSColor+RingTheme.h"
+
+@interface HoverTableRowView ()
+@property BOOL mouseInside;
+@end
+
+@implementation HoverTableRowView
+
+@dynamic mouseInside;
+
+- (instancetype)init
+{
+    self.highlightable = YES;
+}
+
+-  (id)initWithFrame:(CGRect)aRect
+{
+    self = [super initWithFrame:aRect];
+
+    if (self) {
+        self.highlightable = YES;
+    }
+
+    return self;
+}
+
+- (id)initWithCoder:(NSCoder*)aDecoder
+{
+    self = [super initWithCoder:aDecoder];
+    if (self) {
+        self.highlightable = YES;
+    }
+
+    return self;
+}
+
+- (void)dealloc {
+
+}
+
+- (void)setMouseInside:(BOOL)value {
+    if (mouseInside != value) {
+        mouseInside = value;
+        [self setNeedsDisplay:YES];
+    }
+}
+
+- (BOOL)mouseInside {
+    return mouseInside;
+}
+
+- (void)ensureTrackingArea {
+    if (trackingArea == nil) {
+        trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
+                                                    options:NSTrackingInVisibleRect
+                        | NSTrackingActiveAlways
+                        | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
+    }
+}
+
+- (void)updateTrackingAreas {
+    [super updateTrackingAreas];
+    [self ensureTrackingArea];
+    if (![[self trackingAreas] containsObject:trackingArea]) {
+        [self addTrackingArea:trackingArea];
+    }
+}
+
+- (void)mouseEntered:(NSEvent *)theEvent {
+    self.mouseInside = YES;
+}
+
+- (void)mouseExited:(NSEvent *)theEvent {
+    self.mouseInside = NO;
+}
+
+static NSGradient *gradientWithTargetColor(NSColor *targetColor) {
+    NSArray *colors = [NSArray arrayWithObjects:[targetColor colorWithAlphaComponent:0],
+                       targetColor,
+                       targetColor,
+                       [targetColor colorWithAlphaComponent:0], nil];
+    const CGFloat locations[4] = { 0.0, 0.35, 0.65, 1.0 };
+    return [[NSGradient alloc] initWithColors:colors atLocations:locations colorSpace:[NSColorSpace sRGBColorSpace]];
+}
+
+- (void)drawBackgroundInRect:(NSRect)dirtyRect {
+    // Custom background drawing. We don't call super at all.
+    [self.backgroundColor set];
+    // Fill with the background color first
+    NSRectFill(self.bounds);
+
+    // Draw a gradient
+    if (self.mouseInside && self.highlightable) {
+        NSRect selectionRect = NSRect(self.bounds);
+        [[NSColor ringGreyHighlight] setFill];
+        NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:2 yRadius:2];
+        [selectionPath fill];
+    }
+}
+
+- (NSRect)separatorRect {
+    NSRect separatorRect = self.bounds;
+    separatorRect.origin.y = NSMaxY(separatorRect) - 1;
+    separatorRect.size.height = 1;
+    return separatorRect;
+}
+
+// Only called if the table is set with a horizontal grid
+- (void)drawSeparatorInRect:(NSRect)dirtyRect {
+    // Use a common shared method of drawing the separator
+    DrawSeparatorInRect([self separatorRect]);
+}
+
+// Only called if the 'selected' property is yes.
+- (void)drawSelectionInRect:(NSRect)dirtyRect {
+    // Check the selectionHighlightStyle, in case it was set to None
+    if (self.selectionHighlightStyle != NSTableViewSelectionHighlightStyleNone) {
+        // We want a hard-crisp stroke, and stroking 1 pixel will border half on one side and half on another, so we offset by the 0.5 to handle this
+        NSRect selectionRect = NSRect(self.bounds);
+        [[NSColor ringGreyHighlight] setFill];
+        NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:2 yRadius:2];
+        [selectionPath fill];
+    }
+}
+
+// interiorBackgroundStyle is normaly "dark" when the selection is drawn (self.selected == YES) and we are in a key window (self.emphasized == YES). However, we always draw a light selection, so we override this method to always return a light color.
+- (NSBackgroundStyle)interiorBackgroundStyle {
+    return NSBackgroundStyleLight;
+}
+
+- (void)setFrame:(NSRect)frameRect {
+    [super setFrame:frameRect];
+    // We need to invalidate more things when live-resizing since we fill with a gradient and stroke
+    if ([self inLiveResize]) {
+        // Redraw everything if we are using a gradient
+        if (self.selected || self.mouseInside) {
+            [self setNeedsDisplay:YES];
+        } else {
+            // Redraw our horizontal grid line, which is a gradient
+            [self setNeedsDisplayInRect:[self separatorRect]];
+        }
+    }
+}
+
+@end
+
+void DrawSeparatorInRect(NSRect rect) {
+    // Cache the gradient for performance
+    static NSGradient *gradient = nil;
+    if (gradient == nil) {
+        gradient = gradientWithTargetColor([NSColor colorWithSRGBRed:.80 green:.80 blue:.80 alpha:1]);
+    }
+    [gradient drawInRect:rect angle:0];
+}
diff --git a/src/views/NSColor+RingTheme.h b/src/views/NSColor+RingTheme.h
new file mode 100644
index 0000000..5d86a5a
--- /dev/null
+++ b/src/views/NSColor+RingTheme.h
@@ -0,0 +1,32 @@
+/*
+ *  Copyright (C) 2015 Savoir-faire Linux Inc.
+ *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSColor (RingTheme)
+
++ (NSColor*) ringBlue;
++ (NSColor*) ringBlueWithAlpha:(CGFloat) a;
+
++ (NSColor*) ringDarkBlue;
+
++ (NSColor*) ringGreyHighlight;
+
+
+@end
diff --git a/src/views/NSColor+RingTheme.mm b/src/views/NSColor+RingTheme.mm
new file mode 100644
index 0000000..4e0f52e
--- /dev/null
+++ b/src/views/NSColor+RingTheme.mm
@@ -0,0 +1,44 @@
+/*
+ *  Copyright (C) 2015 Savoir-faire Linux Inc.
+ *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#import "NSColor+RingTheme.h"
+
+@implementation NSColor (RingTheme)
+
++ (NSColor*) ringBlue
+{
+    return [NSColor colorWithCalibratedRed:43/255.0 green:180/255.0 blue:201/255.0 alpha:1.0];
+}
+
++ (NSColor*) ringBlueWithAlpha:(CGFloat) a
+{
+    return [NSColor colorWithCalibratedRed:43/255.0 green:180/255.0 blue:201/255.0 alpha:a];
+}
+
++ (NSColor*) ringDarkBlue
+{
+    return [NSColor colorWithCalibratedRed:0/255.0 green:59/255.0 blue:78/255.0 alpha:1.0];
+}
+
++ (NSColor*) ringGreyHighlight
+{
+    return [NSColor colorWithCalibratedRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];
+}
+
+@end
diff --git a/src/views/RingOutlineView.h b/src/views/RingOutlineView.h
index 119d6e0..1ed277c 100644
--- a/src/views/RingOutlineView.h
+++ b/src/views/RingOutlineView.h
@@ -15,17 +15,6 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
- *
- *  Additional permission under GNU GPL version 3 section 7:
- *
- *  If you modify this program, or any covered work, by linking or
- *  combining it with the OpenSSL project's OpenSSL library (or a
- *  modified version of that library), containing parts covered by the
- *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
- *  grants you additional permission to convey the resulting work.
- *  Corresponding Source for a non-source form of such a combination
- *  shall include the source code for the parts of OpenSSL used as well
- *  as that of the covered work.
  */
 
 #import <Cocoa/Cocoa.h>
diff --git a/src/views/RingOutlineView.mm b/src/views/RingOutlineView.mm
index fcb994a..7e9c567 100644
--- a/src/views/RingOutlineView.mm
+++ b/src/views/RingOutlineView.mm
@@ -15,21 +15,12 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
- *
- *  Additional permission under GNU GPL version 3 section 7:
- *
- *  If you modify this program, or any covered work, by linking or
- *  combining it with the OpenSSL project's OpenSSL library (or a
- *  modified version of that library), containing parts covered by the
- *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
- *  grants you additional permission to convey the resulting work.
- *  Corresponding Source for a non-source form of such a combination
- *  shall include the source code for the parts of OpenSSL used as well
- *  as that of the covered work.
  */
 
 #import "RingOutlineView.h"
 
+#import "HoverTableRowView.h" // For the grid drawing shared code
+
 @implementation RingOutlineView
 
 - (NSMenu*)menuForEvent:(NSEvent*)evt
@@ -65,4 +56,46 @@
         [super keyDown:theEvent];
 }
 
+- (CGFloat)yPositionPastLastRow {
+    // Only draw the grid past the last visible row
+    NSInteger numberOfRows = self.numberOfRows;
+    CGFloat yStart = 0;
+    if (numberOfRows > 0) {
+        yStart = NSMaxY([self rectOfRow:numberOfRows - 1]);
+    }
+    return yStart;
+}
+
+- (void)drawGridInClipRect:(NSRect)clipRect {
+    // Only draw the grid past the last visible row
+    CGFloat yStart = [self yPositionPastLastRow];
+    // Draw the first separator one row past the last row
+    yStart += self.rowHeight;
+
+    // One thing to do is smarter clip testing to see if we actually need to draw!
+    NSRect boundsToDraw = self.bounds;
+    NSRect separatorRect = boundsToDraw;
+    separatorRect.size.height = 1;
+    while (yStart < NSMaxY(boundsToDraw)) {
+        separatorRect.origin.y = yStart;
+        DrawSeparatorInRect(separatorRect);
+        yStart += self.rowHeight;
+    }
+}
+
+- (void)setFrameSize:(NSSize)size {
+    [super setFrameSize:size];
+    // We need to invalidate more things when live-resizing since we fill with a gradient and stroke
+    if ([self inLiveResize]) {
+        CGFloat yStart = [self yPositionPastLastRow];
+        if (NSHeight(self.bounds) > yStart) {
+            // Redraw our horizontal grid lines
+            NSRect boundsPastY = self.bounds;
+            boundsPastY.size.height -= yStart;
+            boundsPastY.origin.y = yStart;
+            [self setNeedsDisplayInRect:boundsPastY];
+        }
+    }
+}
+
 @end