diff options
-rw-r--r-- | chrome/browser/browser.cc | 2 | ||||
-rw-r--r-- | chrome/browser/browser.h | 2 | ||||
-rw-r--r-- | chrome/browser/browser.scons | 1 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 18 | ||||
-rw-r--r-- | chrome/common/gfx/chrome_font.h | 21 | ||||
-rw-r--r-- | chrome/common/gfx/chrome_font_mac.mm | 87 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 12 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.h | 4 |
8 files changed, 127 insertions, 20 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 6866cf4..b9c5a56 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -12,6 +12,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_shutdown.h" +#include "chrome/browser/browser_window.h" #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/metrics/user_metrics.h" @@ -54,7 +55,6 @@ #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_url_handler.h" -#include "chrome/browser/browser_window.h" #include "chrome/browser/cert_store.h" #include "chrome/browser/character_encoding.h" #include "chrome/browser/debugger/debugger_window.h" diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 35c615f..fdcb365 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -21,6 +21,7 @@ #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" +#include "chrome/browser/toolbar_model.h" #include "chrome/common/notification_observer.h" #include "chrome/common/pref_member.h" #include "base/gfx/rect.h" @@ -30,7 +31,6 @@ #if defined(OS_WIN) #include "chrome/browser/shell_dialogs.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/toolbar_model.h" #endif class BrowserIdleTimer; diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 5a5f0b4..789cab1 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -719,7 +719,6 @@ if not env.Bit('windows'): 'tab_contents/web_drop_target.cc', 'task_manager.cc', 'task_manager_resource_providers.cc', - 'toolbar_model.cc', 'views/download_tab_view.cc', 'window_sizer.cc', ) diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index 51e42f5..4ea8d61 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -568,6 +568,10 @@ E4A3EB130F4EFCF400596CC2 /* grow_box_view.m in Sources */ = {isa = PBXBuildFile; fileRef = E4A3EB120F4EFCF400596CC2 /* grow_box_view.m */; }; E4A3EB390F4EFF4D00596CC2 /* grow_box.png in Resources */ = {isa = PBXBuildFile; fileRef = E4A3EB380F4EFF4D00596CC2 /* grow_box.png */; }; E4BD52C30F548EBD00591DFA /* new_tab_ui.cc in Sources */ = {isa = PBXBuildFile; fileRef = E4BD520E0F53596600591DFA /* new_tab_ui.cc */; }; + E4BD54D00F55A72100591DFA /* toolbar_model.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF94F0E9D4839009A6919 /* toolbar_model.cc */; }; + E4BD55140F55AB3700591DFA /* text_elider.cc in Sources */ = {isa = PBXBuildFile; fileRef = E4BD55120F55AB3700591DFA /* text_elider.cc */; }; + E4BD55490F55AE6900591DFA /* chrome_font_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E4BD55480F55AE6900591DFA /* chrome_font_mac.mm */; }; + E4BD55C90F55BBC500591DFA /* chrome_font_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = E4BD55C80F55BBC500591DFA /* chrome_font_unittest.cc */; }; E4DCDB9D0F4091C00084059A /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4DCDB9C0F4091BF0084059A /* ApplicationServices.framework */; }; E4DCDC8F0F4091F30084059A /* libWebKitSystemInterfaceLeopard.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4DCDC8E0F4091F30084059A /* libWebKitSystemInterfaceLeopard.a */; }; E4DCDC900F40929C0084059A /* libglue.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 826850180F2FC82E009F6555 /* libglue.a */; }; @@ -2836,6 +2840,11 @@ E4A3EB380F4EFF4D00596CC2 /* grow_box.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = grow_box.png; path = theme/grow_box.png; sourceTree = "<group>"; }; E4BD520E0F53596600591DFA /* new_tab_ui.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = new_tab_ui.cc; path = dom_ui/new_tab_ui.cc; sourceTree = "<group>"; }; E4BD520F0F53596600591DFA /* new_tab_ui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = new_tab_ui.h; path = dom_ui/new_tab_ui.h; sourceTree = "<group>"; }; + E4BD55120F55AB3700591DFA /* text_elider.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = text_elider.cc; sourceTree = "<group>"; }; + E4BD55130F55AB3700591DFA /* text_elider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = text_elider.h; sourceTree = "<group>"; }; + E4BD55480F55AE6900591DFA /* chrome_font_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = chrome_font_mac.mm; sourceTree = "<group>"; }; + E4BD55C80F55BBC500591DFA /* chrome_font_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chrome_font_unittest.cc; sourceTree = "<group>"; }; + E4BD56570F55C96B00591DFA /* text_elider_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = text_elider_unittest.cc; sourceTree = "<group>"; }; E4DCDB9C0F4091BF0084059A /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; }; E4DCDC8E0F4091F30084059A /* libWebKitSystemInterfaceLeopard.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libWebKitSystemInterfaceLeopard.a; path = ../third_party/WebKit/WebKitLibraries/libWebKitSystemInterfaceLeopard.a; sourceTree = SOURCE_ROOT; }; E4F324400EE5CE94002533CE /* extension.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = extension.cc; sourceTree = "<group>"; }; @@ -3882,6 +3891,8 @@ children = ( 4D7BFCA90E9D4D5D009A6919 /* chrome_canvas.cc */, 4D7BFCAA0E9D4D5D009A6919 /* chrome_canvas.h */, + E4BD55480F55AE6900591DFA /* chrome_font_mac.mm */, + E4BD55C80F55BBC500591DFA /* chrome_font_unittest.cc */, 4D7BFCAC0E9D4D5D009A6919 /* chrome_font.h */, 4D7BFCAD0E9D4D5D009A6919 /* color_utils.cc */, 4D7BFCAE0E9D4D5D009A6919 /* color_utils.h */, @@ -3895,6 +3906,9 @@ 4D7BFCB60E9D4D5D009A6919 /* insets.h */, 4D7BFCB70E9D4D5D009A6919 /* path.cc */, 4D7BFCB80E9D4D5D009A6919 /* path.h */, + E4BD56570F55C96B00591DFA /* text_elider_unittest.cc */, + E4BD55120F55AB3700591DFA /* text_elider.cc */, + E4BD55130F55AB3700591DFA /* text_elider.h */, 4D7BFCBC0E9D4D5D009A6919 /* utils.h */, ); path = gfx; @@ -5662,6 +5676,7 @@ 4D7BFA320E9D4912009A6919 /* text_database.cc in Sources */, 4D7BFA370E9D4915009A6919 /* text_database_manager.cc in Sources */, 4D7BFA390E9D4918009A6919 /* thumbnail_database.cc in Sources */, + E4BD54D00F55A72100591DFA /* toolbar_model.cc in Sources */, E4F324600EE5D011002533CE /* url_database.cc in Sources */, 8F51B73AAAF1772ECF9BD180 /* url_fetcher.cc in Sources */, 3AEA44DB19C9D93B63D7A2E4 /* url_fetcher_protect.cc in Sources */, @@ -5693,6 +5708,7 @@ 4D7BFB6D0E9D4C51009A6919 /* bloom_filter_unittest.cc in Sources */, 4D7BFCE10E9D4DC8009A6919 /* bzip2_unittest.cc in Sources */, 826853320F30ADF5009F6555 /* child_process.cc in Sources */, + E4BD55C90F55BBC500591DFA /* chrome_font_unittest.cc in Sources */, 826853380F30AE0C009F6555 /* chrome_plugin_lib.cc in Sources */, 4D7BFB350E9D4C18009A6919 /* chrome_thread_unittest.cc in Sources */, 4D7BFB710E9D4C55009A6919 /* chunk_range_unittest.cc in Sources */, @@ -5771,6 +5787,7 @@ B562E2D50F05834500FB1A4F /* chrome_canvas.cc in Sources */, 4D7BFC280E9D4CEB009A6919 /* chrome_constants.cc in Sources */, 4D7BFC2A0E9D4CED009A6919 /* chrome_counters.cc in Sources */, + E4BD55490F55AE6900591DFA /* chrome_font_mac.mm in Sources */, E4F3256E0EE82C83002533CE /* chrome_paths.cc in Sources */, 4D175916B2FC058793051209 /* chrome_paths_mac.cc in Sources */, 4D7BFC2C0E9D4CF1009A6919 /* chrome_switches.cc in Sources */, @@ -5808,6 +5825,7 @@ 4D7BFC8B0E9D4D35009A6919 /* sqlite_utils.cc in Sources */, 4D7BFC920E9D4D3A009A6919 /* task_queue.cc in Sources */, 534E66C40F311BEC0006B2B2 /* temp_scaffolding_stubs.cc in Sources */, + E4BD55140F55AB3700591DFA /* text_elider.cc in Sources */, 4D7BFC970E9D4D3E009A6919 /* throb_animation.cc in Sources */, 4D7BFC9C0E9D4D46009A6919 /* thumbnail_score.cc in Sources */, E45076AB0F153629003BE099 /* time_format.cc in Sources */, diff --git a/chrome/common/gfx/chrome_font.h b/chrome/common/gfx/chrome_font.h index f4b2a9a..8ac225c 100644 --- a/chrome/common/gfx/chrome_font.h +++ b/chrome/common/gfx/chrome_font.h @@ -20,7 +20,12 @@ class SkTypeface; #if defined(OS_WIN) typedef struct HFONT__* NativeFont; #elif defined(OS_MACOSX) -typedef void* NativeFont; // TODO(port): set the correct type here +#ifdef __OBJC__ +@class NSFont; +#else +class NSFont; +#endif +typedef NSFont* NativeFont; #elif defined(OS_LINUX) class SkTypeface; typedef SkTypeface* NativeFont; @@ -208,6 +213,20 @@ class ChromeFont { int height_; int ascent_; int avg_width_; +#elif defined(OS_MACOSX) + explicit ChromeFont(const std::wstring& font_name, int font_size, int style); + + // Calculate and cache the font metrics. + void calculateMetrics(); + + std::wstring font_name_; + int font_size_; + int style_; + + // Cached metrics, generated at construction + int height_; + int ascent_; + int avg_width_; #endif }; diff --git a/chrome/common/gfx/chrome_font_mac.mm b/chrome/common/gfx/chrome_font_mac.mm new file mode 100644 index 0000000..a553be6 --- /dev/null +++ b/chrome/common/gfx/chrome_font_mac.mm @@ -0,0 +1,87 @@ +// Copyright (c) 2009 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/common/gfx/chrome_font.h" + +#include <Cocoa/Cocoa.h> + +#include "base/logging.h" +#include "base/sys_string_conversions.h" + +// static +ChromeFont ChromeFont::CreateFont(const std::wstring& font_name, + int font_size) { + return ChromeFont(font_name, font_size, NORMAL); +} + +ChromeFont::ChromeFont(const std::wstring& font_name, int font_size, int style) + : font_name_(font_name), + font_size_(font_size), + style_(style) { + calculateMetrics(); +} + +ChromeFont::ChromeFont() + : font_size_([NSFont systemFontSize]), + style_(NORMAL) { + NSFont* system_font = [NSFont systemFontOfSize:font_size_]; + font_name_ = base::SysNSStringToWide([system_font fontName]); + calculateMetrics(); +} + +void ChromeFont::calculateMetrics() { + NSFont* font = nativeFont(); + height_ = [font xHeight]; + ascent_ = [font ascender]; + avg_width_ = [font boundingRectForGlyph:[font glyphWithName:@"x"]].size.width; +} + +ChromeFont ChromeFont::DeriveFont(int size_delta, int style) const { + return ChromeFont(font_name_, font_size_ + size_delta, style); +} + +int ChromeFont::height() const { + return height_; +} + +int ChromeFont::baseline() const { + return ascent_; +} + +int ChromeFont::ave_char_width() const { + return avg_width_; +} + +int ChromeFont::GetStringWidth(const std::wstring& text) const { + NSFont* font = nativeFont(); + NSString* ns_string = base::SysWideToNSString(text); + NSDictionary* attributes = + [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; + NSSize string_size = [ns_string sizeWithAttributes:attributes]; + return string_size.width; +} + +int ChromeFont::GetExpectedTextWidth(int length) const { + return length * avg_width_; +} + +int ChromeFont::style() const { + return style_; +} + +std::wstring ChromeFont::FontName() { + return font_name_; +} + +int ChromeFont::FontSize() { + return font_size_; +} + +NativeFont ChromeFont::nativeFont() const { + // TODO(pinkerton): apply |style_| to font. + // We could cache this, but then we'd have to conditionally change the + // dtor just for MacOS. Not sure if we want to/need to do that. + return [NSFont fontWithName:base::SysWideToNSString(font_name_) + size:font_size_]; +} diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 770bf2c..423acdc 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -356,18 +356,6 @@ ScopableCPRequest::~ScopableCPRequest() { NOTIMPLEMENTED(); } -#if defined(OS_MACOSX) -namespace gfx { -std::wstring GetCleanStringFromUrl(const GURL& url, - const std::wstring& languages, - url_parse::Parsed* new_parsed, - size_t* prefix_end) { - NOTIMPLEMENTED(); - return L""; -} -} -#endif - MemoryDetails::MemoryDetails() { NOTIMPLEMENTED(); } diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index fba6dfc..5025691 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -520,10 +520,6 @@ class DockInfo { void AdjustOtherWindowBounds() const { NOTIMPLEMENTED(); } }; -class ToolbarModel { - public: -}; - class WindowSizer { public: static void GetBrowserWindowBounds(const std::wstring& app_name, |