Auto merge of #7559 - ddrmanxbxfr:RFC-0344-Work, r=nox

Remove 'get_*' on getters as per RFC 0344 on canevas, compositing, devtools, gfx, layout, net, profile, servo and webdriver_server

Hi guys,

I just gave a big pass of RFC-0344 as per issue #6224 .

Pretty much renamed all the get_* fn that were used to fetch values. 

I hope I didn't rename too much. 

As said in the issue discussion, I didn't touch at the scripts folder so we keep the unsafe ones pretty explicit.

I've ran the whole pass of test, everything seems to be still working right :).

Please give feedback on this PR.

Thanks for looking into it.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7559)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-12 18:29:56 -06:00
commit b05f4aa3aa
30 changed files with 167 additions and 168 deletions

View file

@ -41,7 +41,7 @@ pub trait FontHandleMethods: Sized {
fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>;
fn glyph_h_kerning(&self, GlyphId, GlyphId) -> FractionalPixel;
fn metrics(&self) -> FontMetrics;
fn get_table_for_tag(&self, FontTableTag) -> Option<Box<FontTable>>;
fn table_for_tag(&self, FontTableTag) -> Option<Box<FontTable>>;
}
// Used to abstract over the shaper's choice of fixed int representation.
@ -168,8 +168,8 @@ impl Font {
self.shaper.as_ref().unwrap()
}
pub fn get_table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
let result = self.handle.get_table_for_tag(tag);
pub fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
let result = self.handle.table_for_tag(tag);
let status = if result.is_some() { "Found" } else { "Didn't find" };
debug!("{} font table[{}] with family={}, face={}",

View file

@ -2,14 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use platform::font_context::FontContextHandle;
use platform::font_list::get_available_families;
use platform::font_list::get_last_resort_font_families;
use platform::font_list::get_system_default_family;
use platform::font_list::get_variations_for_family;
use font_template::{FontTemplate, FontTemplateDescriptor};
use net_traits::{ResourceTask, load_whole_resource};
use platform::font_context::FontContextHandle;
use platform::font_list::for_each_available_family;
use platform::font_list::for_each_variation;
use platform::font_list::last_resort_font_families;
use platform::font_list::system_default_family;
use platform::font_template::FontTemplateData;
use std::borrow::ToOwned;
use std::collections::HashMap;
@ -42,7 +41,7 @@ impl FontFamily {
// TODO(Issue #190): if not in the fast path above, do
// expensive matching of weights, etc.
for template in &mut self.templates {
let maybe_template = template.get_if_matches(fctx, desc);
let maybe_template = template.data_for_descriptor(fctx, desc);
if maybe_template.is_some() {
return maybe_template;
}
@ -99,7 +98,7 @@ struct FontCache {
fn add_generic_font(generic_fonts: &mut HashMap<LowercaseString, LowercaseString>,
generic_name: &str, mapped_name: &str) {
let opt_system_default = get_system_default_family(generic_name);
let opt_system_default = system_default_family(generic_name);
let family_name = match opt_system_default {
Some(system_default) => LowercaseString::new(&system_default),
None => LowercaseString::new(mapped_name),
@ -115,11 +114,11 @@ impl FontCache {
match msg {
Command::GetFontTemplate(family, descriptor, result) => {
let family = LowercaseString::new(&family);
let maybe_font_template = self.get_font_template(&family, &descriptor);
let maybe_font_template = self.find_font_template(&family, &descriptor);
result.send(Reply::GetFontTemplateReply(maybe_font_template)).unwrap();
}
Command::GetLastResortFontTemplate(descriptor, result) => {
let font_template = self.get_last_resort_font_template(&descriptor);
let font_template = self.last_resort_font_template(&descriptor);
result.send(Reply::GetFontTemplateReply(Some(font_template))).unwrap();
}
Command::AddWebFont(family_name, src, result) => {
@ -145,7 +144,7 @@ impl FontCache {
}
Source::Local(ref local_family_name) => {
let family = &mut self.web_families.get_mut(&family_name).unwrap();
get_variations_for_family(&local_family_name, |path| {
for_each_variation(&local_family_name, |path| {
family.add_template(Atom::from_slice(&path), None);
});
}
@ -162,7 +161,7 @@ impl FontCache {
fn refresh_local_families(&mut self) {
self.local_families.clear();
get_available_families(|family_name| {
for_each_available_family(|family_name| {
let family_name = LowercaseString::new(&family_name);
if !self.local_families.contains_key(&family_name) {
let family = FontFamily::new();
@ -187,7 +186,7 @@ impl FontCache {
let s = self.local_families.get_mut(family_name).unwrap();
if s.templates.is_empty() {
get_variations_for_family(family_name, |path| {
for_each_variation(family_name, |path| {
s.add_template(Atom::from_slice(&path), None);
});
}
@ -217,7 +216,7 @@ impl FontCache {
}
}
fn get_font_template(&mut self, family: &LowercaseString, desc: &FontTemplateDescriptor)
fn find_font_template(&mut self, family: &LowercaseString, desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
let transformed_family_name = self.transform_family(family);
let mut maybe_template = self.find_font_in_web_family(&transformed_family_name, desc);
@ -227,9 +226,9 @@ impl FontCache {
maybe_template
}
fn get_last_resort_font_template(&mut self, desc: &FontTemplateDescriptor)
fn last_resort_font_template(&mut self, desc: &FontTemplateDescriptor)
-> Arc<FontTemplateData> {
let last_resort = get_last_resort_font_families();
let last_resort = last_resort_font_families();
for family in &last_resort {
let family = LowercaseString::new(family);
@ -281,7 +280,7 @@ impl FontCacheTask {
}
}
pub fn get_font_template(&self, family: String, desc: FontTemplateDescriptor)
pub fn find_font_template(&self, family: String, desc: FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
let (response_chan, response_port) = channel();
@ -296,7 +295,7 @@ impl FontCacheTask {
}
}
pub fn get_last_resort_font_template(&self, desc: FontTemplateDescriptor)
pub fn last_resort_font_template(&self, desc: FontTemplateDescriptor)
-> Arc<FontTemplateData> {
let (response_chan, response_port) = channel();

View file

@ -134,7 +134,7 @@ impl FontContext {
/// Create a group of fonts for use in layout calculations. May return
/// a cached font if this font instance has already been used by
/// this context.
pub fn get_layout_font_group_for_style(&mut self, style: Arc<SpecifiedFontStyle>)
pub fn layout_font_group_for_style(&mut self, style: Arc<SpecifiedFontStyle>)
-> Rc<FontGroup> {
let address = &*style as *const SpecifiedFontStyle as usize;
if let Some(ref cached_font_group) = self.layout_font_group_cache.get(&address) {
@ -186,9 +186,9 @@ impl FontContext {
}
if !cache_hit {
let font_template = self.font_cache_task.get_font_template(family.name()
.to_owned(),
desc.clone());
let font_template = self.font_cache_task.find_font_template(family.name()
.to_owned(),
desc.clone());
match font_template {
Some(font_template) => {
let layout_font = self.create_layout_font(font_template,
@ -236,7 +236,7 @@ impl FontContext {
}
if !cache_hit {
let font_template = self.font_cache_task.get_last_resort_font_template(desc.clone());
let font_template = self.font_cache_task.last_resort_font_template(desc.clone());
let layout_font = self.create_layout_font(font_template,
desc.clone(),
style.font_size,
@ -261,7 +261,7 @@ impl FontContext {
/// Create a paint font for use with azure. May return a cached
/// reference if already used by this font context.
pub fn get_paint_font_from_template(&mut self,
pub fn paint_font_from_template(&mut self,
template: &Arc<FontTemplateData>,
pt_size: Au)
-> Rc<RefCell<ScaledFont>> {

View file

@ -88,7 +88,7 @@ impl FontTemplate {
}
/// Get the data for creating a font if it matches a given descriptor.
pub fn get_if_matches(&mut self,
pub fn data_for_descriptor(&mut self,
fctx: &FontContextHandle,
requested_desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
@ -100,13 +100,13 @@ impl FontTemplate {
match self.descriptor {
Some(actual_desc) => {
if *requested_desc == actual_desc {
Some(self.get_data())
Some(self.data())
} else {
None
}
},
None if self.is_valid => {
let data = self.get_data();
let data = self.data();
let handle: Result<FontHandle, ()> =
FontHandleMethods::new_from_template(fctx, data.clone(), None);
match handle {
@ -138,7 +138,7 @@ impl FontTemplate {
/// Get the data for creating a font.
pub fn get(&mut self) -> Option<Arc<FontTemplateData>> {
if self.is_valid {
Some(self.get_data())
Some(self.data())
} else {
None
}
@ -147,7 +147,7 @@ impl FontTemplate {
/// Get the font template data. If any strong references still
/// exist, it will return a clone, otherwise it will load the
/// font data and store a weak reference to it internally.
pub fn get_data(&mut self) -> Arc<FontTemplateData> {
pub fn data(&mut self) -> Arc<FontTemplateData> {
let maybe_data = match self.weak_ref {
Some(ref data) => data.upgrade(),
None => None,

View file

@ -1272,7 +1272,7 @@ impl<'a> PaintContext<'a> {
self.create_draw_target_for_blur_if_necessary(&text.base.bounds, text.blur_radius);
{
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let font = self.font_context.get_paint_font_from_template(
let font = self.font_context.paint_font_from_template(
&text.text_run.font_template, text.text_run.actual_pt_size);
font.borrow()
.draw_text(&temporary_draw_target.draw_target,

View file

@ -320,7 +320,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
}
let new_buffers = (0..tile_count).map(|i| {
let thread_id = i % self.worker_threads.len();
self.worker_threads[thread_id].get_painted_tile_buffer()
self.worker_threads[thread_id].painted_tile_buffer()
}).collect();
let layer_buffer_set = box LayerBufferSet {
@ -483,7 +483,7 @@ impl WorkerThreadProxy {
self.sender.send(msg).unwrap()
}
fn get_painted_tile_buffer(&mut self) -> Box<LayerBuffer> {
fn painted_tile_buffer(&mut self) -> Box<LayerBuffer> {
match self.receiver.recv().unwrap() {
MsgFromWorkerThread::PaintedTile(layer_buffer) => layer_buffer,
}

View file

@ -263,7 +263,7 @@ impl FontHandleMethods for FontHandle {
return metrics;
}
fn get_table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
let tag = tag as FT_ULong;
unsafe {

View file

@ -27,7 +27,7 @@ static FC_FILE: &'static [u8] = b"file\0";
static FC_INDEX: &'static [u8] = b"index\0";
static FC_FONTFORMAT: &'static [u8] = b"fontformat\0";
pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) {
pub fn for_each_available_family<F>(mut callback: F) where F: FnMut(String) {
unsafe {
let config = FcConfigGetCurrent();
let fontSet = FcConfigGetFonts(config, FcSetSystem);
@ -57,7 +57,7 @@ pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) {
}
}
pub fn get_variations_for_family<F>(family_name: &str, mut callback: F)
pub fn for_each_variation<F>(family_name: &str, mut callback: F)
where F: FnMut(String)
{
debug!("getting variations for {}", family_name);
@ -111,7 +111,7 @@ pub fn get_variations_for_family<F>(family_name: &str, mut callback: F)
}
}
pub fn get_system_default_family(generic_name: &str) -> Option<String> {
pub fn system_default_family(generic_name: &str) -> Option<String> {
let generic_name_c = CString::new(generic_name).unwrap();
let generic_name_ptr = generic_name_c.as_ptr();
@ -140,7 +140,7 @@ pub fn get_system_default_family(generic_name: &str) -> Option<String> {
}
#[cfg(target_os = "linux")]
pub fn get_last_resort_font_families() -> Vec<String> {
pub fn last_resort_font_families() -> Vec<String> {
vec!(
"Fira Sans".to_owned(),
"DejaVu Sans".to_owned(),
@ -149,6 +149,6 @@ pub fn get_last_resort_font_families() -> Vec<String> {
}
#[cfg(target_os = "android")]
pub fn get_last_resort_font_families() -> Vec<String> {
pub fn last_resort_font_families() -> Vec<String> {
vec!("Roboto".to_owned())
}

View file

@ -192,7 +192,7 @@ impl FontHandleMethods for FontHandle {
return metrics;
}
fn get_table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
let result: Option<CFData> = self.ctfont.get_font_table(tag);
result.and_then(|data| {
Some(box FontTable::wrap(data))

View file

@ -10,7 +10,7 @@ use core_text::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef};
use std::borrow::ToOwned;
use std::mem;
pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) {
pub fn for_each_available_family<F>(mut callback: F) where F: FnMut(String) {
let family_names = core_text::font_collection::get_family_names();
for strref in family_names.iter() {
let family_name_ref: CFStringRef = unsafe { mem::transmute(strref) };
@ -20,7 +20,7 @@ pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) {
}
}
pub fn get_variations_for_family<F>(family_name: &str, mut callback: F) where F: FnMut(String) {
pub fn for_each_variation<F>(family_name: &str, mut callback: F) where F: FnMut(String) {
debug!("Looking for faces of family: {}", family_name);
let family_collection = core_text::font_collection::create_for_family(family_name);
@ -35,10 +35,10 @@ pub fn get_variations_for_family<F>(family_name: &str, mut callback: F) where F:
}
}
pub fn get_system_default_family(_generic_name: &str) -> Option<String> {
pub fn system_default_family(_generic_name: &str) -> Option<String> {
None
}
pub fn get_last_resort_font_families() -> Vec<String> {
pub fn last_resort_font_families() -> Vec<String> {
vec!("Arial Unicode MS".to_owned(), "Arial".to_owned())
}

View file

@ -242,7 +242,7 @@ impl<'a> DetailedGlyphStore {
self.lookup_is_sorted = false;
}
fn get_detailed_glyphs_for_entry(&'a self, entry_offset: CharIndex, count: u16)
fn detailed_glyphs_for_entry(&'a self, entry_offset: CharIndex, count: u16)
-> &'a [DetailedGlyph] {
debug!("Requesting detailed glyphs[n={}] for entry[off={:?}]", count, entry_offset);
@ -268,7 +268,7 @@ impl<'a> DetailedGlyphStore {
&self.detail_buffer[i .. i + count as usize]
}
fn get_detailed_glyph_with_index(&'a self,
fn detailed_glyph_with_index(&'a self,
entry_offset: CharIndex,
detail_offset: u16)
-> &'a DetailedGlyph {
@ -361,7 +361,7 @@ impl<'a> GlyphInfo<'a> {
match self {
GlyphInfo::Simple(store, entry_i) => store.entry_buffer[entry_i.to_usize()].id(),
GlyphInfo::Detail(store, entry_i, detail_j) => {
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).id
store.detail_store.detailed_glyph_with_index(entry_i, detail_j).id
}
}
}
@ -372,7 +372,7 @@ impl<'a> GlyphInfo<'a> {
match self {
GlyphInfo::Simple(store, entry_i) => store.entry_buffer[entry_i.to_usize()].advance(),
GlyphInfo::Detail(store, entry_i, detail_j) => {
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).advance
store.detail_store.detailed_glyph_with_index(entry_i, detail_j).advance
}
}
}
@ -381,7 +381,7 @@ impl<'a> GlyphInfo<'a> {
match self {
GlyphInfo::Simple(_, _) => None,
GlyphInfo::Detail(store, entry_i, detail_j) => {
Some(store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).offset)
Some(store.detail_store.detailed_glyph_with_index(entry_i, detail_j).offset)
}
}
}
@ -672,7 +672,7 @@ impl<'a> GlyphIterator<'a> {
#[inline(never)]
fn next_complex_glyph(&mut self, entry: &GlyphEntry, i: CharIndex)
-> Option<(CharIndex, GlyphInfo<'a>)> {
let glyphs = self.store.detail_store.get_detailed_glyphs_for_entry(i, entry.glyph_count());
let glyphs = self.store.detail_store.detailed_glyphs_for_entry(i, entry.glyph_count());
self.glyph_range = Some(range::each_index(CharIndex(0), CharIndex(glyphs.len() as isize)));
self.next()
}

View file

@ -103,7 +103,7 @@ impl ShapedGlyphData {
}
/// Returns shaped glyph data for one glyph, and updates the y-position of the pen.
pub fn get_entry_for_glyph(&self, i: usize, y_pos: &mut Au) -> ShapedGlyphEntry {
pub fn entry_for_glyph(&self, i: usize, y_pos: &mut Au) -> ShapedGlyphEntry {
assert!(i < self.count);
unsafe {
@ -170,7 +170,7 @@ impl Shaper {
options: *options,
};
let hb_face: *mut hb_face_t =
RUST_hb_face_create_for_tables(get_font_table_func,
RUST_hb_face_create_for_tables(font_table_func,
(&mut *font_and_shaping_options)
as *mut FontAndShapingOptions
as *mut c_void,
@ -448,7 +448,7 @@ impl Shaper {
if is_bidi_control(character) {
glyphs.add_nonglyph_for_char_index(char_idx, false, false);
} else {
let shape = glyph_data.get_entry_for_glyph(glyph_span.begin(), &mut y_pos);
let shape = glyph_data.entry_for_glyph(glyph_span.begin(), &mut y_pos);
let advance = self.advance_for_shaped_glyph(shape.advance, character, options);
let data = GlyphData::new(shape.codepoint,
advance,
@ -463,7 +463,7 @@ impl Shaper {
let mut datas = vec!();
for glyph_i in glyph_span.each_index() {
let shape = glyph_data.get_entry_for_glyph(glyph_i, &mut y_pos);
let shape = glyph_data.entry_for_glyph(glyph_i, &mut y_pos);
datas.push(GlyphData::new(shape.codepoint,
shape.advance,
shape.offset,
@ -601,7 +601,7 @@ extern fn glyph_h_kerning_func(_: *mut hb_font_t,
}
// Callback to get a font table out of a font.
extern fn get_font_table_func(_: *mut hb_face_t,
extern fn font_table_func(_: *mut hb_face_t,
tag: hb_tag_t,
user_data: *mut c_void)
-> *mut hb_blob_t {
@ -613,7 +613,7 @@ extern fn get_font_table_func(_: *mut hb_face_t,
assert!(!(*font_and_shaping_options).font.is_null());
// TODO(Issue #197): reuse font table data, which will change the unsound trickery here.
match (*(*font_and_shaping_options).font).get_table_for_tag(tag as FontTableTag) {
match (*(*font_and_shaping_options).font).table_for_tag(tag as FontTableTag) {
None => ptr::null_mut(),
Some(font_table) => {
// `Box::into_raw` intentionally leaks the FontTable so we don't destroy the buffer