From 3259aa9cdf3e25c815b7e74da1e836920a544318 Mon Sep 17 00:00:00 2001 From: "thakis@chromium.org" Date: Fri, 9 Jul 2010 04:56:48 +0000 Subject: Mac: Make default plugin appearance match windows. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Still no plugin download functionality. This adds a dependency from default_plugin to app. Since webkit_glue no longer depends on default_plugin, that's ok. BUG=17392 TEST=Go to e.g. http://www.santacruzsurfschool.com/ . The missing plugin view on the right should now look like it does on windows (yellow background, centered plugin icon, localized text below it – http://img43.imageshack.us/img43/6254/missingplugin.gif ). Review URL: http://codereview.chromium.org/2843027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51933 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/chrome.gyp | 1 + chrome/chrome_dll.gypi | 1 + chrome/default_plugin/default_plugin.gyp | 43 +++++++++++++ chrome/default_plugin/default_plugin_resources.grd | 16 +++++ chrome/default_plugin/plugin_impl_mac.h | 12 ++++ chrome/default_plugin/plugin_impl_mac.mm | 70 ++++++++++++++-------- 6 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 chrome/default_plugin/default_plugin_resources.grd diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 5f76955..de32666 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1762,6 +1762,7 @@ 'pak_inputs': [ '<(grit_out_dir)/browser_resources.pak', '<(grit_out_dir)/common_resources.pak', + '<(grit_out_dir)/default_plugin_resources/default_plugin_resources.pak', '<(grit_out_dir)/renderer_resources.pak', '<(grit_out_dir)/theme_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/app/app_resources/app_resources.pak', diff --git a/chrome/chrome_dll.gypi b/chrome/chrome_dll.gypi index 9761d79..01544ad 100644 --- a/chrome/chrome_dll.gypi +++ b/chrome/chrome_dll.gypi @@ -320,6 +320,7 @@ 'pak_inputs': [ '<(grit_out_dir)/browser_resources.pak', '<(grit_out_dir)/common_resources.pak', + '<(grit_out_dir)/default_plugin_resources/default_plugin_resources.pak', '<(grit_out_dir)/renderer_resources.pak', '<(grit_out_dir)/theme_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/app/app_resources/app_resources.pak', diff --git a/chrome/default_plugin/default_plugin.gyp b/chrome/default_plugin/default_plugin.gyp index b2852bf..a0d8a6d 100644 --- a/chrome/default_plugin/default_plugin.gyp +++ b/chrome/default_plugin/default_plugin.gyp @@ -5,12 +5,16 @@ { 'variables': { 'chromium_code': 1, + 'grit_info_cmd': ['python', '../../tools/grit/grit_info.py',], + 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/chrome', + 'grit_cmd': ['python', '../../tools/grit/grit.py'], }, 'targets': [ { 'target_name': 'default_plugin', 'type': '<(library)', 'dependencies': [ + ':default_plugin_resources', '<(DEPTH)/net/net.gyp:net_resources', '<(DEPTH)/third_party/icu/icu.gyp:icui18n', '<(DEPTH)/third_party/icu/icu.gyp:icuuc', @@ -56,6 +60,45 @@ }], ], }, + # This can't be part of chrome.gyp:chrome_resources because then there'd + # be a cyclic dependency. + { + 'target_name': 'default_plugin_resources', + 'type': 'none', + 'actions': [ + { + 'action_name': 'default_plugin_resources', + 'variables': { + 'input_path': 'default_plugin_resources.grd', + }, + 'inputs': [ + ' + + + + + + + + + + + + + + + diff --git a/chrome/default_plugin/plugin_impl_mac.h b/chrome/default_plugin/plugin_impl_mac.h index 9e3b7fc..f2d10a8 100644 --- a/chrome/default_plugin/plugin_impl_mac.h +++ b/chrome/default_plugin/plugin_impl_mac.h @@ -11,6 +11,14 @@ #include "gfx/native_widget_types.h" #include "third_party/npapi/bindings/npapi.h" +#ifdef __OBJ__ +@class NSImage; +@class NSString; +#else +class NSImage; +class NSString; +#endif + // Possible plugin installer states. enum PluginInstallerState { PluginInstallerStateUndefined, @@ -277,6 +285,10 @@ class PluginInstallerImpl { // Dimensions of the plugin uint32_t width_; uint32_t height_; + // Plugin icon + NSImage* image_; + // Displayed text + NSString* command_; DISALLOW_COPY_AND_ASSIGN(PluginInstallerImpl); }; diff --git a/chrome/default_plugin/plugin_impl_mac.mm b/chrome/default_plugin/plugin_impl_mac.mm index 253e786..9c8bff4 100644 --- a/chrome/default_plugin/plugin_impl_mac.mm +++ b/chrome/default_plugin/plugin_impl_mac.mm @@ -6,11 +6,14 @@ #import +#include "app/l10n_util_mac.h" +#include "app/resource_bundle.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/string_util.h" #include "chrome/default_plugin/plugin_main.h" #include "googleurl/src/gurl.h" +#include "grit/default_plugin_resources.h" #include "grit/webkit_strings.h" #include "unicode/locid.h" #include "webkit/glue/webkit_glue.h" @@ -19,10 +22,14 @@ // TODO(thakis): Most methods in this class are stubbed out and need to be // implemented. -PluginInstallerImpl::PluginInstallerImpl(int16 mode) { +PluginInstallerImpl::PluginInstallerImpl(int16 mode) + : image_(nil), + command_(nil) { } PluginInstallerImpl::~PluginInstallerImpl() { + [image_ release]; + [command_ release]; } bool PluginInstallerImpl::Initialize(void* module_handle, NPP instance, @@ -40,6 +47,12 @@ bool PluginInstallerImpl::Initialize(void* module_handle, NPP instance, instance_ = instance; mime_type_ = mime_type; + command_ = [l10n_util::FixUpWindowsStyleLabel(webkit_glue::GetLocalizedString( + IDS_DEFAULT_PLUGIN_NO_PLUGIN_AVAILABLE_MSG)) retain]; + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + image_ = [rb.GetNSImageNamed(IDR_PLUGIN_ICON) retain]; + return true; } @@ -125,42 +138,49 @@ void PluginInstallerImpl::DownloadCancelled() { } int16 PluginInstallerImpl::OnDrawRect(CGContextRef context, CGRect dirty_rect) { - const NSString* text = @"Missing Plug-in"; - const float kTextMarginX = 6; - const float kTextMarginY = 1; - NSSize bounds = NSMakeSize(width_, height_); - [NSGraphicsContext saveGraphicsState]; NSGraphicsContext* ns_context = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES]; [NSGraphicsContext setCurrentContext:ns_context]; + // Fill background. + NSColor* bg_color = [NSColor colorWithCalibratedRed:252 / 255.0 + green:235 / 255.0 + blue:162 / 255.0 + alpha:1.0]; + [bg_color setFill]; + NSRectFill(NSRectFromCGRect(dirty_rect)); + + [[NSColor blackColor] set]; + NSFrameRect(NSMakeRect(0, 0, width_, height_)); + + // Drag image. + DCHECK(image_); + if (image_) { + NSPoint point = NSMakePoint((width_ - [image_ size].width) / 2, + (height_ + [image_ size].height) / 2); + [image_ dissolveToPoint:point fraction:1.0]; + } + + // Draw text. NSShadow* shadow = [[[NSShadow alloc] init] autorelease]; - [shadow setShadowColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.5]]; + [shadow setShadowColor:[NSColor colorWithDeviceWhite:1.0 alpha:0.5]]; [shadow setShadowOffset:NSMakeSize(0, -1)]; - NSFont* font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]; + NSFont* font = [NSFont systemFontOfSize: + [NSFont systemFontSizeForControlSize:NSSmallControlSize]]; NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, - [NSColor whiteColor], NSForegroundColorAttributeName, + [NSColor blackColor], NSForegroundColorAttributeName, shadow, NSShadowAttributeName, nil]; - NSSize text_size = [text sizeWithAttributes:attributes]; - NSRect text_rect; - text_rect.size.width = text_size.width + 2*kTextMarginX; - text_rect.size.height = text_size.height + 2*kTextMarginY; - text_rect.origin.x = (bounds.width - NSWidth(text_rect))/2; - text_rect.origin.y = (bounds.height - NSHeight(text_rect))/2; - - [[NSColor colorWithCalibratedWhite:0.52 alpha:1.0] setFill]; - [[NSBezierPath bezierPathWithRoundedRect:text_rect - xRadius:NSHeight(text_rect)/2 - yRadius:NSHeight(text_rect)/2] fill]; - - NSPoint label_point = NSMakePoint( - roundf(text_rect.origin.x + (text_rect.size.width - text_size.width)/2), - roundf(text_rect.origin.y + (text_rect.size.height - text_size.height)/2)); - [text drawAtPoint:label_point withAttributes:attributes]; + NSSize text_size = [command_ sizeWithAttributes:attributes]; + NSPoint label_point = NSMakePoint((width_ - text_size.width) / 2, + (height_ - text_size.height) / 2); + if (image_) + label_point.y += [image_ size].height / 2 + text_size.height / 2 + 10; + label_point = NSMakePoint(roundf(label_point.x), roundf(label_point.y)); + [command_ drawAtPoint:label_point withAttributes:attributes]; [NSGraphicsContext restoreGraphicsState]; return 1; -- cgit v1.1