summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/cocoa/extensions')
-rw-r--r--chrome/browser/cocoa/extensions/browser_actions_controller.mm3
-rw-r--r--chrome/browser/cocoa/extensions/chevron_menu_button.h19
-rw-r--r--chrome/browser/cocoa/extensions/chevron_menu_button.mm15
-rw-r--r--chrome/browser/cocoa/extensions/chevron_menu_button_cell.h19
-rw-r--r--chrome/browser/cocoa/extensions/chevron_menu_button_cell.mm47
-rw-r--r--chrome/browser/cocoa/extensions/chevron_menu_button_unittest.mm50
6 files changed, 152 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm
index 8295ee9..0d49b7a 100644
--- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm
@@ -14,6 +14,7 @@
#import "chrome/browser/cocoa/extensions/browser_action_button.h"
#import "chrome/browser/cocoa/extensions/browser_actions_container_view.h"
#import "chrome/browser/cocoa/extensions/extension_popup_controller.h"
+#import "chrome/browser/cocoa/extensions/chevron_menu_button.h"
#import "chrome/browser/cocoa/menu_button.h"
#include "chrome/browser/extensions/extension_browser_event_router.h"
#include "chrome/browser/extensions/extension_host.h"
@@ -775,7 +776,7 @@ class ExtensionsServiceObserverBridge : public NotificationObserver,
return;
if (!chevronMenuButton_.get()) {
- chevronMenuButton_.reset([[MenuButton alloc] init]);
+ chevronMenuButton_.reset([[ChevronMenuButton alloc] init]);
[chevronMenuButton_ setBordered:NO];
[chevronMenuButton_ setShowsBorderOnlyWhileMouseInside:YES];
NSImage* chevronImage = nsimage_cache::ImageNamed(kOverflowChevronsName);
diff --git a/chrome/browser/cocoa/extensions/chevron_menu_button.h b/chrome/browser/cocoa/extensions/chevron_menu_button.h
new file mode 100644
index 0000000..ea4ccc2
--- /dev/null
+++ b/chrome/browser/cocoa/extensions/chevron_menu_button.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_COCOA_EXTENSIONS_CHEVRON_MENU_BUTTON_H_
+#define CHROME_BROWSER_COCOA_EXTENSIONS_CHEVRON_MENU_BUTTON_H_
+#pragma once
+
+#import "chrome/browser/cocoa/menu_button.h"
+
+@interface ChevronMenuButton : MenuButton {
+}
+
+// Overrides cell class with |ChevronMenuButtonCell|.
++ (Class)cellClass;
+
+@end
+
+#endif // CHROME_BROWSER_COCOA_EXTENSIONS_CHEVRON_MENU_BUTTON_H_
diff --git a/chrome/browser/cocoa/extensions/chevron_menu_button.mm b/chrome/browser/cocoa/extensions/chevron_menu_button.mm
new file mode 100644
index 0000000..37159ae
--- /dev/null
+++ b/chrome/browser/cocoa/extensions/chevron_menu_button.mm
@@ -0,0 +1,15 @@
+// Copyright (c) 2010 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.
+
+#include "chrome/browser/cocoa/extensions/chevron_menu_button.h"
+
+#include "chrome/browser/cocoa/extensions/chevron_menu_button_cell.h"
+
+@implementation ChevronMenuButton
+
++ (Class)cellClass {
+ return [ChevronMenuButtonCell class];
+}
+
+@end
diff --git a/chrome/browser/cocoa/extensions/chevron_menu_button_cell.h b/chrome/browser/cocoa/extensions/chevron_menu_button_cell.h
new file mode 100644
index 0000000..c3217e3
--- /dev/null
+++ b/chrome/browser/cocoa/extensions/chevron_menu_button_cell.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_COCOA_EXTENSIONS_CHEVRON_MENU_BUTTON_CELL_H_
+#define CHROME_BROWSER_COCOA_EXTENSIONS_CHEVRON_MENU_BUTTON_CELL_H_
+#pragma once
+
+#import "chrome/browser/cocoa/clickhold_button_cell.h"
+
+@interface ChevronMenuButtonCell : ClickHoldButtonCell {
+}
+
+// Adds a gradient border to the RHS of the cell when not hovered.
+- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView;
+
+@end
+
+#endif // CHROME_BROWSER_COCOA_EXTENSIONS_CHEVRON_MENU_BUTTON_CELL_H_
diff --git a/chrome/browser/cocoa/extensions/chevron_menu_button_cell.mm b/chrome/browser/cocoa/extensions/chevron_menu_button_cell.mm
new file mode 100644
index 0000000..6a8b829
--- /dev/null
+++ b/chrome/browser/cocoa/extensions/chevron_menu_button_cell.mm
@@ -0,0 +1,47 @@
+// Copyright (c) 2010 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.
+
+#include "chrome/browser/cocoa/extensions/chevron_menu_button_cell.h"
+
+namespace {
+
+// Width of the divider.
+const CGFloat kDividerWidth = 1.0;
+
+// Vertical inset from edge of cell to divider start.
+const CGFloat kDividerInset = 3.0;
+
+// Grayscale for the center of the divider.
+const CGFloat kDividerGrayscale = 0.5;
+
+} // namespace
+
+@implementation ChevronMenuButtonCell
+
+- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
+ [super drawWithFrame:cellFrame inView:controlView];
+
+ if ([self isMouseInside])
+ return;
+
+ NSColor* middleColor =
+ [NSColor colorWithCalibratedWhite:kDividerGrayscale alpha:1.0];
+ NSColor* endPointColor = [middleColor colorWithAlphaComponent:0.0];
+
+ // Blend from background to |kDividerGrayscale| and back to
+ // background.
+ scoped_nsobject<NSGradient> borderGradient([[NSGradient alloc]
+ initWithColorsAndLocations:endPointColor, (CGFloat)0.0,
+ middleColor, (CGFloat)0.5,
+ endPointColor, (CGFloat)1.0,
+ nil]);
+
+ NSRect edgeRect, remainder;
+ NSDivideRect(cellFrame, &edgeRect, &remainder, kDividerWidth, NSMaxXEdge);
+ edgeRect = NSInsetRect(edgeRect, 0.0, kDividerInset);
+
+ [borderGradient drawInRect:edgeRect angle:90.0];
+}
+
+@end
diff --git a/chrome/browser/cocoa/extensions/chevron_menu_button_unittest.mm b/chrome/browser/cocoa/extensions/chevron_menu_button_unittest.mm
new file mode 100644
index 0000000..e5c2f77
--- /dev/null
+++ b/chrome/browser/cocoa/extensions/chevron_menu_button_unittest.mm
@@ -0,0 +1,50 @@
+// Copyright (c) 2010 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 "chrome/browser/cocoa/extensions/chevron_menu_button.h"
+#import "chrome/browser/cocoa/extensions/chevron_menu_button_cell.h"
+
+#include "base/scoped_nsobject.h"
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+
+namespace {
+
+class ChevronMenuButtonTest : public CocoaTest {
+ public:
+ ChevronMenuButtonTest() {
+ NSRect frame = NSMakeRect(0, 0, 50, 30);
+ scoped_nsobject<ChevronMenuButton> button(
+ [[ChevronMenuButton alloc] initWithFrame:frame]);
+ button_ = button.get();
+ [[test_window() contentView] addSubview:button_];
+ }
+
+ ChevronMenuButton* button_;
+};
+
+// Test basic view operation.
+TEST_VIEW(ChevronMenuButtonTest, button_);
+
+// |ChevronMenuButton exists entirely to override the cell class.
+TEST_F(ChevronMenuButtonTest, CellSubclass) {
+ EXPECT_TRUE([[button_ cell] isKindOfClass:[ChevronMenuButtonCell class]]);
+}
+
+// Test both hovered and non-hovered display.
+TEST_F(ChevronMenuButtonTest, HoverAndNonHoverDisplay) {
+ ChevronMenuButtonCell* cell = [button_ cell];
+ EXPECT_FALSE([cell showsBorderOnlyWhileMouseInside]);
+ EXPECT_FALSE([cell isMouseInside]);
+
+ [cell setShowsBorderOnlyWhileMouseInside:YES];
+ [cell mouseEntered:nil];
+ EXPECT_TRUE([cell isMouseInside]);
+ [button_ display];
+
+ [cell mouseExited:nil];
+ EXPECT_FALSE([cell isMouseInside]);
+ [button_ display];
+}
+
+} // namespace